快排实现

来源:互联网 发布:mac dock栏动态效果 编辑:程序博客网 时间:2024/05/10 15:55
   #include<stdio.h>
#include<stdlib.h>
int quick_sort(int a[],int low,int high)
{
    if(low<high)
    {
  int tem,t=a[low];
       int l=low,h=high;
  while(l<h) 
       { 
     while(a[h]>t) h--;
     while(a[l]<t) l++;
     if(h>l)
       {
    tem = a[l];
    a[l] = a[h];
    a[h] = tem;
        }
       }
    quick_sort(a,low,l-1);
quick_sort(a,l+1,high);
    }


}
int main()
{
int a[10]={8,3,5,32,56,73,2,64,745,35};
int i;
quick_sort(a,0,9);
for(i=0;i<10;i++)
    printf("%d ",a[i]);
    system("pause");
}
0 0
原创粉丝点击