-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2-3.cpp
More file actions
39 lines (38 loc) · 853 Bytes
/
Copy path2-3.cpp
File metadata and controls
39 lines (38 loc) · 853 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 part(vector<int> &nums, int l, int r)
{
int pivot = nums[l];
int i = l + 1, j = r;
while (true)
{
while (i <= j && nums[i] <= pivot)
i++;
while (i <= j && nums[j] >= pivot)
j--;
if (i > j)
break;
swap(nums[i], nums[j]);
}
swap(nums[j], nums[l]);
return j;
}
void QuickSort(vector<int> &nums, int l, int r)
{
if (l < r)
{
int mid = part(nums, l, r);
QuickSort(nums, l, mid - 1);
QuickSort(nums, mid + 1, r);
}
}
int main(){
vector<int> a;
int n,k;
for (int i=(cin>>n,0);i<n;i++)
a.push_back((cin>>k,k));
QuickSort(a,0,a.size()-1);
for (auto it = a.begin();it!=a.end();it++)
cout<<*it<<(*it == a[a.size()-1]?"\n":" ");
return 0;
}