-
Notifications
You must be signed in to change notification settings - Fork 1
/
new.cpp
74 lines (53 loc) · 844 Bytes
/
new.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//recursion quick sort
#include <bits/stdc++.h>
using namespace std;
#define ll long
void swap(int *first, int *second){
int temp;
temp = *first;
*first = *second;
*second = temp;
}
int partition(int *a,int s, int e){
// int j =s;
int pivot = a[e];
int i=s-1;
for(int j=s;j<=e-1;j++){
if(a[i]<pivot){
i=i+1;
swap(a[i],a[j]);
}
// j=j+1;
}
swap(a[i+1],a[e]);
return i+1;
}
void solve(int *a,int s,int e){
if(s>=e){
return;
}
int p = partition(a,s,e);
// printfn(a,n);
solve(a,s,p-1);
solve(a,p+1,e);
}
void printfn(int *a,int n){
for(int i=0;i<n;i++){
cout<<a[i]<<" ";
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("inputs.txt","r",stdin);
freopen("outputs.txt","w",stdout);
#endif
int a[1000],n;
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
solve(a,0,n-1);
printfn(a,n);
return 0;
}