diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 8603c7a..6190522 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -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) diff --git a/cpp/algorithms/sorting/bubble/lib-bubble.cpp b/cpp/algorithms/sorting/bubble/lib-bubble.cpp index 17810f0..008cb20 100644 --- a/cpp/algorithms/sorting/bubble/lib-bubble.cpp +++ b/cpp/algorithms/sorting/bubble/lib-bubble.cpp @@ -15,9 +15,9 @@ void BubbleSort(std::vector &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]); diff --git a/cpp/algorithms/sorting/count/lib-counting.cpp b/cpp/algorithms/sorting/count/lib-counting.cpp index 36b5139..bbfd796 100644 --- a/cpp/algorithms/sorting/count/lib-counting.cpp +++ b/cpp/algorithms/sorting/count/lib-counting.cpp @@ -33,7 +33,7 @@ void CountingSort(std::vector &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 } diff --git a/cpp/algorithms/sorting/heap/lib-heap.cpp b/cpp/algorithms/sorting/heap/lib-heap.cpp index 0c1840e..4a04d6e 100644 --- a/cpp/algorithms/sorting/heap/lib-heap.cpp +++ b/cpp/algorithms/sorting/heap/lib-heap.cpp @@ -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 &array, size_t thisIndex, const int &heapSize) +void MaxHeapify(std::vector &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); diff --git a/cpp/algorithms/sorting/heap/lib-heap.hpp b/cpp/algorithms/sorting/heap/lib-heap.hpp index d05bb42..f0df433 100644 --- a/cpp/algorithms/sorting/heap/lib-heap.hpp +++ b/cpp/algorithms/sorting/heap/lib-heap.hpp @@ -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 &array, size_t thisIndex, const int &heapSize); +void MaxHeapify(std::vector &array, size_t thisIndex, const size_t &heapSize); void BuildMaxHeap(std::vector &array); diff --git a/cpp/algorithms/sorting/insertion/lib-insertion.cpp b/cpp/algorithms/sorting/insertion/lib-insertion.cpp index b6aa11d..6510449 100644 --- a/cpp/algorithms/sorting/insertion/lib-insertion.cpp +++ b/cpp/algorithms/sorting/insertion/lib-insertion.cpp @@ -15,7 +15,7 @@ void InsertionSort(std::vector &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]; diff --git a/cpp/algorithms/sorting/quick/lib-quick.cpp b/cpp/algorithms/sorting/quick/lib-quick.cpp index 435226b..16eda75 100644 --- a/cpp/algorithms/sorting/quick/lib-quick.cpp +++ b/cpp/algorithms/sorting/quick/lib-quick.cpp @@ -50,7 +50,7 @@ size_t Partition(std::vector &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]); diff --git a/cpp/algorithms/sorting/radix/lib-counting.cpp b/cpp/algorithms/sorting/radix/lib-counting.cpp index 702fe12..bbb70f9 100644 --- a/cpp/algorithms/sorting/radix/lib-counting.cpp +++ b/cpp/algorithms/sorting/radix/lib-counting.cpp @@ -41,7 +41,7 @@ void CountingSort(std::vector &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]; } diff --git a/cpp/algorithms/sorting/selection/lib-select.cpp b/cpp/algorithms/sorting/selection/lib-select.cpp index d22946b..15980e5 100644 --- a/cpp/algorithms/sorting/selection/lib-select.cpp +++ b/cpp/algorithms/sorting/selection/lib-select.cpp @@ -12,10 +12,10 @@ #include void SelectionSort(std::vector &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 } diff --git a/cpp/cryptography/columnar-transposition/lib-cipher.cpp b/cpp/cryptography/columnar-transposition/lib-cipher.cpp index 03d5a3f..a4235d2 100644 --- a/cpp/cryptography/columnar-transposition/lib-cipher.cpp +++ b/cpp/cryptography/columnar-transposition/lib-cipher.cpp @@ -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); diff --git a/cpp/multithreading/CMakeLists.txt b/cpp/multithreading/CMakeLists.txt new file mode 100644 index 0000000..e69de29 diff --git a/cpp/multithreading/race-condition/CMakeLists.txt b/cpp/multithreading/race-condition/CMakeLists.txt new file mode 100644 index 0000000..e69de29