-
Notifications
You must be signed in to change notification settings - Fork 0
/
quicksort.cpp
55 lines (44 loc) · 1.04 KB
/
quicksort.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//BISMILLAHIR RAHMANIR RAHEEM
//ALLAH IS WATCHING ME
// Shoeb Akibul Islam
// Dept of ICE, NSTU
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii= pair<int,int>;
const int N=200005;
ll mod= 1e9+7;
int p_tion(vector<int>&a, int l, int h){
int p = a[h], i = l - 1; /// p means pivot;
for(int j = l; j< h; j ++){
if(a[j] < p)
swap(a[++i], a[j]);
}
swap(a[i+1],a[h]);
return i+1;
}
void quicksort(vector<int> &a, int l, int h){
if(l >= h)return;
int pos = p_tion(a, l, h);
quicksort(a, l, pos-1);
quicksort(a, pos+1, h);
}
void solve(int tc)
{
vector<int> a({6,7,5,2,8,0,12,9,14,6,2});
int n = a.size();
quicksort(a, 0, n-1);
for(auto i: a)
cout << i << ' ';
cout << '\n';
}
signed main()
{
int test_case=1;
// ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// cin >> test_case;
for(int i = 1; i <= test_case ; i++)
solve(i);
return 0;
}
/// Alhamdulillah...