/*
name:vivi
data:2020.4.2
title:quick sort
*/
#include<stdio.h>
int pos(int a[],int low,int high)
{
int i = low;
int j = high;
int temp = a[low]; //选取枢轴
while(i < j)
{
while(i<j && temp <= a[j])
j--;
a[i] = a[j];
while(i<j && temp >= a[i])
i++;
a[j] = a[i];
}
a[i] = temp;
return i;
}
void quick_sort(int a[],int low,int high)
{
if(low<high)
{
int p = pos(a,low,high);
quick_sort(a,low,p-1);
quick_sort(a,p+1,high);
}
}
int main()
{
int a[10] = {4,0,8,1,15,2,6,11,9,3};
int i;
quick_sort(a,0,9);
for(i = 0;i < 10;i++)
printf("%d ",a[i]);
return 0;
}
vivi 快速排序 C语言实现
最新推荐文章于 2024-06-03 23:00:06 发布