快速排序 c++ 实现

#include 
using namespace std;
void qsort(int Arr[],int left,int right){
	if(left>=right){
		return;
	}
	int flg  = Arr[left];
	int i = left;
	int j = right;
	while(i<j){
		for(;i<j&&Arr[j]>=flg;j--);
		if(i<j)
			Arr[i] = Arr[j];
		for(;i<j&&Arr[i]<=flg;i++);
		if(i<j)
			Arr[j] = Arr[i];
	}
	Arr[i] = flg;
	qsort(Arr,left,i-1);
	qsort(Arr,i+1,right);
}

int main(){
	int Array[] = {213,243,345,52,1,57,112,6,12,56,2131,34,65,324,123,47,3,23,346,56,12,3122,3,58,23,3,234};
	qsort(Array,0,sizeof(Array)/sizeof(int)-1);
	for(int i = 0;i<sizeof(Array)/sizeof(int);i++){
		cout<<Array[i]<<endl;
	}
} 

你可能感兴趣的:(hihoCoder)