From 07c25626c74c2275282681fc29294efee5d9f998 Mon Sep 17 00:00:00 2001 From: lok2327 Date: Mon, 4 Apr 2022 06:04:59 +0900 Subject: [PATCH] assignment week4 --- main.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index 39d17e2..7c6e673 100644 --- a/main.cpp +++ b/main.cpp @@ -142,7 +142,18 @@ void bubble_sort_descending(int* array, unsigned int size) { { //####################################################### //Implement here - ; + for(unsigned int l=0; l < size-1-i; l++){ + + if(array[l] < array[l+1]){ + + int lok = array[l]; + + array[l] = array[l+1]; + array[l+1] = lok; + + } + + } //####################################################### } } @@ -152,7 +163,23 @@ void insertion_sort_descending(int* array, unsigned int size) { { //####################################################### //Implement here - ; + int lok = array[i]; + int k = i-1; + + while(true){ + + if(k < 0) break; + + if(array[k] >= lok) break; + + array[k+1] = array[k]; + + k -= 1; + + } + + array[k+1] = lok; + //####################################################### } } @@ -162,7 +189,23 @@ void selection_sort_descending(int* array, unsigned int size) { { //####################################################### //Implement here - ; + int maximum = array[i]; + int maximum_index = i; + + for(unsigned int r = i+1; r < size; r++){ + + if(array[r] > maximum){ + + maximum = array[r]; + + maximum_index = r; + + } + + } + + swap(array[i], array[maximum_index]); + //####################################################### } }