-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick_sort.cpp
More file actions
76 lines (72 loc) · 1.57 KB
/
quick_sort.cpp
File metadata and controls
76 lines (72 loc) · 1.57 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*------------------------------------------------------
author : Aritra Chowdhury
created : Sunday | 26 May,2024 | 22:45:43
------------------------------------------------------*/
#include <bits/stdc++.h>
#include <string>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
#define read(type) readInt<type>() // Fast read
#define ll long long
#define nL "\n"
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define a first
#define b second
#define vi vector<int>
#define vi vector<int>
#define vll vector<long long>
#define vs vector<string>
#define all(x) (x).begin(), (x).end()
#define umap unordered_map
#define uset unordered_set
#define MOD 1000000007
#define imax INT_MAX
#define imin INT_MIN
#define exp 1e9
#define sz(x) (int((x).size()))
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int partition(int a[],int p,int r)
{
int x = a[r];
int i = p;
for(int j = p; j < r-1; j++)
{
if(a[j] <= x)
{
i++;
swap(a[i],a[j]);
}
}
swap(a[i],a[r]);
return i;
}
void quickSort(int a[],int p,int r)
{
if(p < r)
{
int q = partition(a,p,r);
quickSort(a,p,q-1);
quickSort(a,q+1,r);
}
}
int main()
{
int n;
cin >> n;
int a[n];
for(int i = 0; i < n; i++)
{
cin >> a[i];
}
quickSort(a,0,n-1);
for(int i = 0; i < n; i++)
{
cout << a[i] << " ";
}
}