[cpp] Add -Wall compiler option to root CMakeLists

+ Resolve all warnings
This commit is contained in:
Shaun Reed 2022-03-31 17:35:47 -04:00
parent a97dfbe34b
commit fc1f247987
12 changed files with 15 additions and 14 deletions

View File

@ -18,6 +18,7 @@ project(
)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_compile_options("-Wall")
add_subdirectory(algorithms)
add_subdirectory(cmake-example)

View File

@ -15,9 +15,9 @@
void BubbleSort(std::vector<int> &array)
{
// For each value within the set, starting at 0
for (int sortedPivot = 0; sortedPivot < array.size(); sortedPivot++) {
for (size_t sortedPivot = 0; sortedPivot < array.size(); sortedPivot++) {
// Check every other remaining value in the set
for (int j = array.size() - 1; j > sortedPivot; j--) {
for (size_t j = array.size() - 1; j > sortedPivot; j--) {
// Swap if the value at j is less than the value before it
if (array[j] < array[j - 1]) {
std::swap(array[j], array[j - 1]);

View File

@ -33,7 +33,7 @@ void CountingSort(std::vector<int> &array)
// Count the values less than or equal to each element of tempArray
// + Since each element stores its own count, just add the count at index i-1
for (size_t i = 1; i <= maxValue; i++) {
for (int32_t i = 1; i <= maxValue; i++) {
tempArray[i] += tempArray[i - 1];
// tempArray[i] - 1 now represents the sorted 0-index pos for each value i
}

View File

@ -17,7 +17,7 @@ size_t Parent(const size_t &index) { return index / 2;}
size_t Left(const size_t &index) { return 2 * index + 1;}
size_t Right(const size_t &index) { return (2 * index) + 2;}
void MaxHeapify(std::vector<int> &array, size_t thisIndex, const int &heapSize)
void MaxHeapify(std::vector<int> &array, size_t thisIndex, const size_t &heapSize)
{
// Get an index for the left and right nodes attached to thisIndex
size_t l = Left(thisIndex);

View File

@ -18,7 +18,7 @@ size_t Parent(const size_t &index);
size_t Left(const size_t &index);
size_t Right(const size_t &index);
void MaxHeapify(std::vector<int> &array, size_t thisIndex, const int &heapSize);
void MaxHeapify(std::vector<int> &array, size_t thisIndex, const size_t &heapSize);
void BuildMaxHeap(std::vector<int> &array);

View File

@ -15,7 +15,7 @@ void InsertionSort(std::vector<int> &array)
{
// For each value, move left until we find sortedPosition for keyValue
// + Starting with keyValue at array[1], to check sortedPosition at array[0]
for (int keyIndex = 1; keyIndex <= array.size(); keyIndex++) {
for (size_t keyIndex = 1; keyIndex <= array.size(); keyIndex++) {
// Save the current key value
// + We will look for the sorted position of this value
const int keyValue = array[keyIndex];

View File

@ -50,7 +50,7 @@ size_t Partition(std::vector<int> &array, size_t begin, size_t end)
// + Return this value when done, so we know where the lhs partition ends
ssize_t lhsIndex = begin - 1;
// For each value within this partition, check for values < keyValue
for (int j = begin; j <= end - 1; j++) {
for (size_t j = begin; j <= end - 1; j++) {
if (array[j] <= keyValue) {
// Swap all values < keyValue into the lhs portion of array
std::swap(array[++lhsIndex], array[j]);

View File

@ -41,7 +41,7 @@ void CountingSort(std::vector<int> &array, int placeValue)
// Count the values less than or equal to each element of tempArray
// + Since each element stores its own count, just add the count at index i-1
for (int i = 1; i < tempArray.size(); i++) {
for (size_t i = 1; i < tempArray.size(); i++) {
tempArray[i] = tempArray[i] + tempArray[i - 1];
}

View File

@ -12,10 +12,10 @@
#include <vector>
void SelectionSort(std::vector<int> &arr) {
for (int leftIndex = 0; leftIndex < arr.size(); leftIndex++) {
for (size_t leftIndex = 0; leftIndex < arr.size(); leftIndex++) {
// Get the index for the minimum number in the unsorted set
int min = leftIndex;
for (int i = leftIndex; i < arr.size(); i++) {
size_t min = leftIndex;
for (size_t i = leftIndex; i < arr.size(); i++) {
// Check if value at i is smaller than value at min index
min = (arr[min] > arr[i]) ? i : min; // Update min value to i if true
}

View File

@ -21,9 +21,9 @@ void Columnar::InitOrder(std::string temp)
temp.erase(it, temp.end());
// Step through each character in lexicographic order
for (int i = 0; i < temp.size(); i++) {
for (size_t i = 0; i < temp.size(); i++) {
// Check each character in the keyWord for the current lexicographic char
for (int j = 0; j < keyWord_.size(); j++) {
for (size_t j = 0; j < keyWord_.size(); j++) {
// If they are equal, push the index of the char in keyWord to orderVect
if (keyWord_[j] == temp[i]) {
orderVect_.push_back(j);
@ -109,7 +109,7 @@ std::string Columnar::Decrypt(std::string message)
rows.resize(orderVect_.size());
// Track the ending position after each substring is taken
int lastPos = 0;
for (int i = 0; i < orderVect_.size(); i++) {
for (size_t i = 0; i < orderVect_.size(); i++) {
// If we are assigning to any row < fullRows, it should have + 1 character
if (orderVect_[i] < fullRows) {
rows[orderVect_[i]] = message.substr(lastPos, rowLength + 1);

View File