Browse Source

fixed mixed signs

Kajetan Johannes Hammerle 3 years ago
parent
commit
7009e8850b
2 changed files with 6 additions and 6 deletions
  1. 2 2
      bubble_sort/Main.cpp
  2. 4 4
      selection_sort/Main.cpp

+ 2 - 2
bubble_sort/Main.cpp

@@ -28,7 +28,7 @@ void bubbleSort(T* in, int size, int (*key)(const T&)) {
     // make the bubble sort
     do {
         madeSwap = false;
-        for (unsigned int i = 0; i < size - 1; i++) {
+        for (int i = 0; i < size - 1; i++) {
             // if this element is bigger that the next one swap places
             if (key(in[i]) > key(in[i + 1])) {
                 madeSwap = true;
@@ -115,4 +115,4 @@ int main() {
     structTest();
     pointerTest();
     return 0;
-}
+}

+ 4 - 4
selection_sort/Main.cpp

@@ -24,12 +24,12 @@ int randomInt() {
 
 template<typename T>
 void selectionSort(T* in, int size, int (*key)(const T&)) {
-    unsigned int minValue;
+    int minValue;
     // move boundry of unsorted array one by one
-    for (unsigned int i = 0; i < size - 1; i++) {
+    for (int i = 0; i < size - 1; i++) {
         // find the minimum element in the unsorted array
         minValue = i;
-        for (unsigned int j = i + 1; j < size; j++) {
+        for (int j = i + 1; j < size; j++) {
             if (key(in[j]) < key(in[minValue])) {
                 minValue = j;
             }
@@ -117,4 +117,4 @@ int main() {
     structTest();
     pointerTest();
     return 0;
-}
+}