-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickSort.cpp
More file actions
39 lines (32 loc) · 803 Bytes
/
quickSort.cpp
File metadata and controls
39 lines (32 loc) · 803 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <bits/stdc++.h>
using namespace std;
int getIndex(vector<int>& array,int low,int high){
int tem = array[low];
while(low<high){
while(low<high&&array[high]>=tem){
high--;
}
array[low] = array[high];
while(low<high&&array[low]<=tem){
low++;
}
array[high] = array[low];
}
array[low] = tem;
return low;
}
void quick(vector<int>& array,int low,int high){
if(low<high){
int index = getIndex(array,low,high);
quick(array,0,index-1);
quick(array,index+1,high);
}
}
int main(){
vector<int> arr{49, 38, 65, 97, 23, 22, 76, 1, 5, 8, 2, 0, -1, 22};
quick(arr,0,arr.size()-1);
for(int i=0;i<arr.size();i++){
cout<<arr[i]<<endl;
}
system("pause");
}