淘先锋技术网

首页 1 2 3 4 5 6 7
#include<stdio.h>
#define N 10
int low,high;
int a[N];
 int partition(int a[],int low,int high)
 {
 	int pivot;
 	pivot=a[low];//取数组的第一个元素为枢轴元素 
 	while(low<high)
	 {
	 	while(a[high]>=pivot&&low<high) high--;
		 a[low]=a[high];
		 while(a[low<=pivot]&&low<high) low++;
		 a[high]=a[low]; 
	  } 
	  a[low]=pivot;
	  return low;
 }
void quicksort(int a[],int low,int high)
{
	if(low<high)//递归跳出条件 
	{
	int m=partition(a,low,high);
	quicksort(a,low,m-1);
	quicksort(a,m+1,high);
}
 } 

 int main()
 {
 	int i;
 	for(i=0;i<N;i++)
 	{
 		scanf("%d",&a[i]);
	 }
	 quicksort(a,0,9);
	 for(i=0;i<N;i++)
	 {
	 	printf("%d\t",a[i]);
	 }
	 return 0;
 }