Browse Source

[cpp] Add -Wall compiler option to root CMakeLists

+ Resolve all warnings
master
Shaun Reed 3 months ago
parent
commit
fc1f247987
  1. 1
      cpp/CMakeLists.txt
  2. 4
      cpp/algorithms/sorting/bubble/lib-bubble.cpp
  3. 2
      cpp/algorithms/sorting/count/lib-counting.cpp
  4. 2
      cpp/algorithms/sorting/heap/lib-heap.cpp
  5. 2
      cpp/algorithms/sorting/heap/lib-heap.hpp
  6. 2
      cpp/algorithms/sorting/insertion/lib-insertion.cpp
  7. 2
      cpp/algorithms/sorting/quick/lib-quick.cpp
  8. 2
      cpp/algorithms/sorting/radix/lib-counting.cpp
  9. 6
      cpp/algorithms/sorting/selection/lib-select.cpp
  10. 6
      cpp/cryptography/columnar-transposition/lib-cipher.cpp
  11. 0
      cpp/multithreading/CMakeLists.txt
  12. 0
      cpp/multithreading/race-condition/CMakeLists.txt

1
cpp/CMakeLists.txt

@ -18,6 +18,7 @@ project( @@ -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)

4
cpp/algorithms/sorting/bubble/lib-bubble.cpp

@ -15,9 +15,9 @@ @@ -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]);

2
cpp/algorithms/sorting/count/lib-counting.cpp

@ -33,7 +33,7 @@ void CountingSort(std::vector<int> &array) @@ -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
}

2
cpp/algorithms/sorting/heap/lib-heap.cpp

@ -17,7 +17,7 @@ size_t Parent(const size_t &index) { return index / 2;} @@ -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);

2
cpp/algorithms/sorting/heap/lib-heap.hpp

@ -18,7 +18,7 @@ size_t Parent(const size_t &index); @@ -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);

2
cpp/algorithms/sorting/insertion/lib-insertion.cpp

@ -15,7 +15,7 @@ void InsertionSort(std::vector<int> &array) @@ -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];

2
cpp/algorithms/sorting/quick/lib-quick.cpp

@ -50,7 +50,7 @@ size_t Partition(std::vector<int> &array, size_t begin, size_t end) @@ -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]);

2
cpp/algorithms/sorting/radix/lib-counting.cpp

@ -41,7 +41,7 @@ void CountingSort(std::vector<int> &array, int placeValue) @@ -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];
}

6
cpp/algorithms/sorting/selection/lib-select.cpp

@ -12,10 +12,10 @@ @@ -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
}

6
cpp/cryptography/columnar-transposition/lib-cipher.cpp

@ -21,9 +21,9 @@ void Columnar::InitOrder(std::string temp) @@ -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) @@ -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);

0
cpp/multithreading/CMakeLists.txt

0
cpp/multithreading/race-condition/CMakeLists.txt

Loading…
Cancel
Save