/* QSORT Algorithm (p87 of K&R) with a randomized pivot choice. Defines sort on a sub array of left <= location <= right of an array of integers */ #include #include void QSortRandom(int v[], int left, int right){ int pivot,last,i; if(left>=right) /* If left=right there is a single array element it is already sorted */ return; /* Select "random" element as pivot */ pivot=left+(rand()*(right-left))/RAND_MAX; printf("%i\n",pivot); printf("%i\n",RAND_MAX+1); /* pivot= (left+right)/2; */ /* Puts the pivot value in the left hand location makes it easy to sweep through the rest of the elements */ Swap(v,left,pivot); /* last is the last location in the subarray that has been tested <= the pivot value */ last=left; for(i=left+1; i<=right; i++){ /* sweeps through the array if v[i]< pivot is moved left and stays put otherwise. last is incremented to keep track of the split point */ if(v[i]