普通快速排序代码如下:
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
int getindex(vector<int>&arr,int m,int left,int right){
bool flag=true;
while(left<right){
if(flag){
if(arr[right]>=m){
right--;
}
else{
arr[left++]=arr[right];
flag = false;
}
}
else{
if(arr[left]<=m){
left++;
}
else{
arr[right--]=arr[left];
flag=true;
}
}
}
arr[left]=m;
return left;
}
void quicksort(vector<int>&arr,int left,int right){
int mid= getindex(arr,arr[left],left,right);
if(left<mid-1)
quicksort(arr,left,mid-1);
if(right>mid+1)
quicksort(arr,mid+1,right);
}
int main(){
vector<int>arr={1,5,3,9,4,56,234,71,3,52,7};
quicksort(arr,0,arr.size()-1);
for(int t:arr){
cout<<t<<" ";
}
}