#include<stdio.h>
void quickSort(int *,int,int);
int findPoss(int *,int,int);
int main()
{
int i;
int arry[] = {8,9,0,-3,6,7,-11};
quickSort(arry,0,6);
printf("After sorted:\n");
for(i=0;i<7;i++)
printf("%d ",arry[i]);
printf("\n");
return 0;
}
void quickSort(int *a,int low,int high)
{
int pos;
if(low < high)
{
pos = findPoss(a,low,high);
quickSort(a,low,pos-1);
quickSort(a,pos+1,high);
}
return ;
}
int findPoss(int *a,int low,int high)
{
int val = a[low];
while(low < high)
{
while(low<high && a[high]>=val)
high--;
a[low] = a[high];
while(low<high && a[low]<=val)
low++;
a[high] = a[low];
}
a[low] = val;
return low;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步