c语言的快速排序法

#include<stdio.h>

int main()

{

int a[10]={21,23,55,77,99,23,44,66,88,13};

int low=0;

int high=9;

int qpass(int a[],int low,int high);

void qsort(int a[],int low,int high);

qsort(a,low,high);

for(int i=0;i<10;i++)

{

printf("%6d",a[i]);

}

return 0;

}


int qpass(int a[],int low,int high)

{

int x=a[low];

int key=a[low];

while(low<high)

{

while(low<high && a[high]>key)

high--;

if(low<high)

{

a[low]=a[high];

low++;

}

while(low<high && a[low]<=key)

low++;

if(low<high)

{

a[high]=a[low];

high--;

}

a[low]=x;

}

return low;

}


void qsort(int a[],int low,int high)

{

if(low<high)

{

int pos=qpass(a,low,high);

qsort(a,low,pos-1);

qsort(a,pos+1,high);

}

}


本文出自 “hagar” 博客,谢绝转载!

你可能感兴趣的:(c,快速排序法)