diff --git a/main.cpp b/main.cpp index 39d17e2..39a78ee 100644 --- a/main.cpp +++ b/main.cpp @@ -139,33 +139,48 @@ void swap(int& a, int& b) { void bubble_sort_descending(int* array, unsigned int size) { for (unsigned int i = 0; i < size - 1; i++) - { - //####################################################### - //Implement here - ; - //####################################################### - } + for (unsigned int j = 0; j < size - 1 - i; j++) + { + if (array[j] < array[j + 1]) + { + int temp; + temp = array[j]; + array[j] = array[j + 1]; + array[j + 1] = temp; + } + } } void insertion_sort_descending(int* array, unsigned int size) { for (unsigned int i = 1; i < size; i++) { - //####################################################### - //Implement here - ; - //####################################################### + int temp = array[i]; + int j = i - 1; + while(1) + { + if (j<0) break; + if (array[j] >= temp) break; + array[j + 1] = array [j]; + j = j - 1; + } + array[j + 1] = temp; } } void selection_sort_descending(int* array, unsigned int size) { for (unsigned int i = 0; i < size - 1; i++) { - //####################################################### - //Implement here - ; - //####################################################### + int min = array[i]; + int min_idx = i; + for (unsigned int j = i + 1; j < size; j++) + { + if (array[j] > min) { + min = array[j]; + min_idx = j; + } + } + swap(array[i], array[min_idx]); } -} - + }