void QuickSort1 (int *s,int left,int right)
{
int i,j,t,pivot;
if (left>right)
Return
if (left<right)
{
Pivot = s[left];//Base Number
I=left;
J=right;
while (I!=J)
{
while (I<j &&s[j]>=pivot) j--; Find the first number smaller than the base number from right to left
while (I<j &&s[i]<=pivot) i++;//from left to right find the first number larger than the base number
if (I<J)//Exchange two number
{
T=s[i];
S[I]=S[J];
s[j]=t;
}
}
S[left] = s[i];//The number of reference digits
S[i] = pivot;
QuickSort1 (s,left,i-1);
QuickSort1 (S,i+1,right);
}
}
void QuickSort2 (int *s,int left,int right)
{
int i,j,pivot;
if (left>right)
Return
if (left<right)
{
Pivot = s[left];//Base Number
I=left;
J=right;
while (I!=J)
{
while (I<j &&s[j]>=pivot) j--; Find the first number smaller than the base number from right to left
if (I<J)
{
S[I]=S[J];
i++;
}
while (I<j &&s[i]<=pivot) i++;//from left to right find the first number larger than the base number
if (I<J)
{
S[j]=s[i];
j--;
}
}
S[i] = pivot;//The number of reference digits
QuickSort2 (s,left,i-1);
QuickSort2 (S,i+1,right);
}
}
int main ()
{
int a[10] = {1,6,7,0,2,17,13,35,19,23};
QuickSort1 (a,0,9);
QuickSort2 (a,0,9);
int i=0;
for (; i<10;i++)
printf ("%d", a[i]);
return 0;
}
C++quicksort