http://blog.csdn.net/morewindows/article/details/6684558#
Dictation: (the error is marked with yellow)
int partition (int s[], int left, int. right) {int i = left;int J = Right;int x =S[0];--------should be s[left]----is not necessarily a non-zero start AH. while (I < j)---------------because I=j is the time to end this small process. So, at the moment of i=j, it's okay to stop. {while (i<=J&&S[J]<x)-----------While (i<j&&s[j]>=x)"Two-while requires a =x" J--;s[i] = s[j];-----------------------if (i<j)------because the while may be i=j, here is guaranteed to pits at unequal times, and move
{S[I]=S[J];
i++;}while (i <= j&&s[i] > x)-----------similarly,s[i]<x;I++;S[J] = s[i];} S[i] = x;return x;--------------------------return is the pit, not the thing in the pit return I}void quick_sort (int s[], int left,int right) {if (s = = null| | Left>=right)------Here about an empty check ... It's weird---- It's a problem to be solved. Returnint g = partition (S, left, right), Quick_sort (s, left, g-1),--------------------recursive Quick_sort (s, left + 1, right); }
When you integrate into a function,
Attention:
① to set the return value to void
② checks the size of left and right at the very beginning----if you do not check for a stack overflow----The reason is that the final recursion is to be g-1 and g+1, if not checked out of range.
dsa-interview-Quick Sort Notes