快速排序降序
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int quick_sort(int arr[],int low,int high)
{
//基准值
int key=arr[low];
int low1=low,high1=high;
if(low>=high) return 0;
while(low<high)
{
//high开始比较
while(low1<high1&&arr[high1]<=key)
{
high1--;}
if(low1<high1)
{
arr[low1++]=arr[high1];
}
//low那边开始比较
while(low1<high1&&arr[low1]>key)
{
low1++;
}
if(low1<high1)
{
arr[high1--]=arr[low1];
}
arr[low1]=key;
quick_sort(arr,low,low1-1);
quick_sort(arr,low1+1,high);
return low;
}
}
int main(int argc, const char *argv[])
{
int arr[]={50,4,8,0,99};
int len=sizeof(arr)/sizeof(arr[0]);
quick_sort(arr,0,len-1);
for(int i=0;i<len;i++)
{
printf("%d ",arr[i]);
}
puts("");
return 0;
}