#include<stdio.h>
void quickSort(int a[], int start, int end);
void main(){
int arr[10] = {
4, 6, 9, 1, 0, 2, 3, 8, 7, 5
};
quickSort(arr, 0, 9);
for(int i=0; i<10; i++){
printf("%d ", arr[i]);
}
}
void quickSort(int a[], int start, int end){
int i, j, temp;
i = start;
j = end;
if(a==NULL)
return;
while(i<j){
while((i<j)&&(a[j]>=a[i])){
j--;
}
if(i<j){
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
while((i<j)&&(a[i]<=a[j])){
i++;
}
if(i<j){
temp = a[j];
a[j] = a[i];
a[i] = temp;
}
}
if(i-start>1){
quickSort(a, 0, i-1);
}
if(end-j>1){
quickSort(a, j+1, end);
}
}
快速排序
最新推荐文章于 2021-11-19 16:57:43 发布