Hi! I've been studying quick sort. I stumbled across this piece of code:
Was using the debugging feature in DevC++. Found some amusing behaviour which led me to the following conclusions..Am I right in assuming that during recursive calls to quicksort, the values of left and right passed by value rather than reference?Code:void quicksort(int arr[], int left, int right) { int i = left, j = right; int tmp; int pivot = arr[(left + right) / 2]; /* partition */ while (i <= j) { while (arr[i] < pivot) i++; while (arr[j] > pivot) j--; if (i <= j) { tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp; i++; j--; } }; /* recursion */ if (left < j) quicksort(arr, left, j); if (i < right) quicksort(arr, i, right); }
If not, I am seriously bugged! because I dont seem to get Quick Sort step by step at all although I get the general concept! Thanks!



LinkBack URL
About LinkBacks




Btw, how good is this code? I mean, are there any better code examples for quick sort that this one?