快速排序

#include<bits/stdc++.h>
using namespace std;
void quick_sort(int* A,int l,int r){
	if(l>=r) return;
	int s=A[l],p=l,q=r;
	while(p<q){
		while(p<q&&s<=A[q]) q--;
			A[p]=A[q];
		while(p<q&&s>=A[p]) p++;
			A[q]=A[p];
	}
	A[q]=s;
	for(int i=0;i<10;i++){
		printf("%d ",A[i]);
	}
	printf("\n");
	quick_sort(A,l,p-1);
	quick_sort(A,p+1,r);
}


int main()
{
	int a[10]={7,8,9,6,3,2,5,4,0,1};
	
	quick_sort(a,0,9);
	for(int i=0;i<10;i++){
		printf("%d ",a[i]);
	}
	return 0;
 } 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章