-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickSort.cpp
More file actions
49 lines (44 loc) · 1.04 KB
/
QuickSort.cpp
File metadata and controls
49 lines (44 loc) · 1.04 KB
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
40
41
42
43
44
45
46
47
48
49
/*************************************************************************
> File Name: QuickSort.cpp
> Author: sukingw
> Mail: [email protected]
> Created Time: Mon 28 Aug 2017 05:09:15 PM CST
************************************************************************/
// 快速排序练习
#include<iostream>
#include<vector>
using namespace std;
int partation(vector<int> &a,int s, int e){
int partkey = a[s];
while(s<e){
while(s<e && a[e]>=partkey){
e--;
}
swap(a[s],a[e]);
while(s<e&&a[s]<= partkey){
s++;
}
swap(a[s],a[e]);
}
}
void QuickSort(vector<int> &a,int s,int e){
if(s<e){
int part;
part = partation(a,s,e);
QuickSort(a,s,part-1);
QuickSort(a,part+1,e);
}
}
int main(){
int a;
vector<int> input;
while(cin>>a){
input.push_back(a);
}
QuickSort(input,0,input.size()-1);
for(auto it = input.begin();it != input.end();++it){
cout<<*it<< " ";
}
cout<<endl;
return 0;
}