1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
int partition(int arr[], int low, int high){
int pivotkey = arr[low]; int index = 0; int temp = 0;
while(low < high){ while(low < high && arr[high] >= pivotkey) high--; temp = arr[low]; arr[low] = arr[high]; arr[high] = temp;
while(low < high && arr[low] <= pivotkey) low++; temp = arr[low]; arr[low] = arr[high]; arr[high] = temp; } arr[low] = pivotkey;
for(index = 0; index <= 5; index++){ printf("%d\t", arr[index]); } printf("\n"); return low; }
void qsort(int arr[], int low, int high){
if(low < high){ int retIndex = partition(arr, low, high); qsort(arr, low, retIndex - 1); qsort(arr, retIndex + 1, high); } }
|