#include <iostream> using namespace std; void display_arr(int *an_array){ int i; for (i = 0; i < 9; i++){ cout << an_array[i] << ", "; } cout << endl; } int partition(int array[], int l, int h){ int i, p, firsthigh; p = h; firsthigh = l; display_arr(array); for (i = l; i < h; i++){ if (array[i] < array[p]){ cout << i << ", " << h << ", " << firsthigh << endl; swap(array[i], array[firsthigh]); firsthigh++; display_arr(array); } } swap(array[p], array[firsthigh]); return firsthigh; } void quicksort(int array[], int l, int h){ int p; if ((h-l) > 0) { p = partition(array, l, h); quicksort(array, l, p-1); quicksort(array, p+1, h); } } int main() { int myarray[9]; int i; for (i = 0; i < 9; i++){ cin >> myarray[i]; } quicksort(myarray, 0, 8); display_arr(myarray); return 0; }
9 3 8 7 1 2 6 5 4
9, 3, 8, 7, 1, 2, 6, 5, 4, 1, 8, 0 3, 9, 8, 7, 1, 2, 6, 5, 4, 4, 8, 1 3, 1, 8, 7, 9, 2, 6, 5, 4, 5, 8, 2 3, 1, 2, 7, 9, 8, 6, 5, 4, 3, 1, 2, 4, 9, 8, 6, 5, 7, 1, 2, 0 1, 3, 2, 4, 9, 8, 6, 5, 7, 1, 2, 3, 4, 9, 8, 6, 5, 7, 6, 8, 4 1, 2, 3, 4, 6, 8, 9, 5, 7, 7, 8, 5 1, 2, 3, 4, 6, 5, 9, 8, 7, 1, 2, 3, 4, 6, 5, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 7, 8, 7 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9,