#include <iostream>
using namespace std;
void Quicksort(int e[],int first,int end){
int i = first, j = end;
int temp = e[i];
while(i<j){
while(i<j && temp<=e[j]){
j--;
}
e[i] = e[j];
while(i<j && e[i]<= temp){
i++;
}
e[j] = e[i];
}
e[i] = temp;
if(first<i-1){
Quicksort(e,first,i-1);
}
if(end>i+1){
Quicksort(e,i+1,end);
}
}
int main() {
int a[10]={1,4,32,12,3,4,2,7,5,7};
Quicksort(a,0,9);
for(int i = 0; i <10 ;++i){
cout<<a[i]<<" ";
}
cout<<endl;
return 0;
}
【面试准备】快排
最新推荐文章于 2024-03-09 17:10:06 发布