- Notifications
You must be signed in to change notification settings - Fork 9.1k
/
Copy pathSolution.cpp
31 lines (26 loc) · 661 Bytes
/
Solution.cpp
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
#include<iostream>
usingnamespacestd;
constint N = 1e6 + 10;
int n;
int nums[N];
voidquick_sort(int nums[], int left, int right) {
if (left >= right) return;
int i = left - 1, j = right + 1;
int x = nums[left + right >> 1];
while (i < j) {
while (nums[++i] < x)
;
while (nums[--j] > x)
;
if (i < j) swap(nums[i], nums[j]);
}
quick_sort(nums, left, j);
quick_sort(nums, j + 1, right);
}
intmain() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%d", &nums[i]);
quick_sort(nums, 0, n - 1);
for (int i = 0; i < n; ++i) printf("%d ", nums[i]);
}