-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1005.cpp
More file actions
39 lines (37 loc) · 859 Bytes
/
Copy path1005.cpp
File metadata and controls
39 lines (37 loc) · 859 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 temp[1002]{0};
void quickSort(int* arr, int len, int layer = 0) {
if (len <= 1) return;
int flag = arr[0];
int p = 0;
for (int i = 1; i < len; i++) {
if (arr[i] < flag) {
swap(arr[i], arr[++p]);
}
}
swap(arr[0], arr[p]);
if (layer >= 1) return;
quickSort(arr, p, layer + 1);
quickSort(arr + p + 1, len - p - 1, layer + 1);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int m;
cin >> m;
while(m--) {
int n;
cin >> n;
int* arr = new int[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
quickSort(arr, n);
for (int i = 0; i < n; i++) {
cout << arr[i] << (i == n - 1 ? '\n' : ' ');
}
delete[] arr;
}
return 0;
}