Quick sort——快速排序,执行效率更高的一种排序方法,代码如下:
#include<stdio.h>
void quicksort(int *num,int left,int right);
int main(void){
int arr[10],i;
for(i = 0;i < 10;i++){
scanf("%d",&arr[i]);
}
quicksort(arr,0,9);
for(i = 0;i < 10;i++)
printf("%d ",arr[i]);
return 0;
}
void quicksort(int *num,int left,int right){
int x,y,z,t;
if(left > right)
return ;
x = num[left];
y = left;
z = right;
while(y != z){
while(num[z] >= x && y < z)
z–;
while(num[y] <= x && y < z)
y++;
if(y < z){
t = num[y];
num[y] = num[z];
num[z] = t;
}
}
num[left] = num[y];
num[y] = x;
quicksort(num,left,y-1);
quicksort(num,y + 1,right);
}
Quick sort
最新推荐文章于 2024-11-15 09:46:08 发布