#include #include using namespace std; #define SIZE 8 /* Function prototypes */ void bubbleSort(int array[], int size, bool ascending = true); void selectionSort(int array[], int size, bool ascending = true); int main(void) { int tarray[] = {2,1,3,1,4,6,5,10,8}; /*bubbleSort(tarray, SIZE, false);*/ selectionSort(tarray,SIZE,false); for (int i = 0; i < SIZE; i++) { cout << tarray[i] << " "; } } void bubbleSort(int array[], int size, bool ascending) { int temp = 0; for(int i=0;i array[i+1]) && ascending) { temp = array[i]; array[i] = array[i+1]; array[i+1] = temp; } else if((array[i] < array[i+1]) && !ascending) { temp = array[i]; array[i] = array[i+1]; array[i+1] = temp; } } } } void selectionSort(int array[], int size, bool ascending) { int highest = 0; int tempI; int temp = 0; int lowest = INT_MAX; for(int i=0;i highest) { highest = array[h]; tempI = h; } } temp = array[i]; array[i] = highest; array[tempI] = temp; } else { int lowest = INT_MAX; for(int j=i;j