#include<stdio.h> |
#include<stdlib.h> |
#include<time.h> |
void quickSort( int a[], int left, int right) |
{ |
int i,j,temp; |
i=left; |
j=right; |
temp=a[left]; |
if (left>right) |
return ; |
while (i!=j) /*找到最终位置*/ |
{ |
while (a[j]>=temp && j>i) |
j--; |
if (j>i) |
a[i++]=a[j]; |
while (a[i]<=temp && j>i) |
i++; |
if (j>i) |
a[j--]=a[i]; |
} |
a[i]=temp; |
quickSort(a,left,i-1); /*递归左边*/ |
quickSort(a,i+1,right); /*递归右边*/ |
} |
int main(){ |
int i; |
int a[10]; |
srand ((unsigned) time (NULL)); |
for (i=0;i<10;i++){ |
a[i]= rand ()%100+1; |
|
} |
quickSort(a,0,9); /*排好序的结果*/ |
for (i=0;i<10;i++) |
printf ( "%4d\n" ,a[i]); |
} |