快速排序
普通快速排序代码如下
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
int getindex(vector<int>&arr,int left,int right){
int m=arr[left];
while(left<right){
while(left<right&&arr[right]>=m)
right--;
arr[left]=arr[right];
while(left<right&&arr[left]<=m)
left++;
arr[right]=arr[left];
}
arr[left]=m;
return left;
}
void quicksort(vector<int>&arr,int left,int right){
if(left<right){
int mid= getindex(arr,left,right);
quicksort(arr,left,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<<" ";
}
}