📄 8.c
字号:
#include<stdio.h>
int times=0;
void quicksort(int data[],int low,int high){
int i,pivot,j;
if(low<high){
pivot = data[low];i=low;j=high;
while(i<j){
while(i<j&&data[j]>=pivot){times++;j--;}
if(i<j)data[i++]=data[j];
while(i<j&&data[i]<=pivot){times++;i++;}
if(i<j)data[j--]=data[i];
}
data[i]=pivot;
quicksort(data,low,i-1);
quicksort(data,i+1,high);
}
}
void main()
{
int i,low,high;
int list[9];
low = 0;high = 9;
for (i=0;i<10;i++)
{
printf("Input num %d:",i);
scanf("%d",&list[i]);
}
printf("\nThe list is:");
for(i=0;i<10;i++)printf("%d ",list[i]);
quicksort(list,0,9);
printf("\nThe sorted list is:");
for(i=0;i<10;i++)printf("%d ",list[i]);
printf("\nThe compare times is:%d",times);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -