-
Notifications
You must be signed in to change notification settings - Fork 15
/
Quick Sort.txt
59 lines (55 loc) · 1.15 KB
/
Quick Sort.txt
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
50
51
52
53
54
55
56
57
58
59
#include <iostream>
using namespace std;
#define pb push_back
#define mk make_pair
#define fop first
#define sop second
#define ll long long int
#define vi vector<ll>
#define vs vector<string>
#define print(a) cout << a
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test(string,a) cout<<string<<a
#define FEI(el,s) for(int el : s)
#define FOR(index,a,n) for (int index = a; index < n; index++)
#define FORD(index,a,n) for (ll index = a; index >= n; index--)
#define NL cout<<"\n"
#define TAB '\t'
int partition(int a[], int low, int high){
int pivot = a[high];
int i = low - 1;
FOR(j,low,high){
if ( a[j] <= pivot ) {
i++;
int temp = a[i];
a[i] = a[j];
a[j] = temp;
//swap(a[i],a[j]);
}
}
int temp = a[i+1];
a[i+1] = a[high];
a[high] = temp;
//swap(a[i+1],a[high]);
return i+1;
}
void quicksort(int a[], int low, int high) {
if ( low < high ) {
int pivot = partition(a, low, high);
quicksort(a,low,pivot-1);
quicksort(a,pivot+1,high);
}
}
int main() {
int t,n; cin >> t;
while(t--) {
cin >> n;
int a[n];
FOR(i,0,n) {
cin >> a[i];
}
quicksort(a,0,n-1);
FEI(el,a)
print(el)<<TAB;
}
}