-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathsort_012.cpp
More file actions
66 lines (61 loc) · 1.06 KB
/
Copy pathsort_012.cpp
File metadata and controls
66 lines (61 loc) · 1.06 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
/*
@Author - Jatin Goel
@Institute - IIIT Allahabad
Hardwork definitely pays off.
There is no substitute of hardwork.
There is no shortcut to success.
*/
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define F first
#define S second
#define fast_io ios::sync_with_stdio(false);cin.tie(NULL)
int sort_012(int a[],int n)
{
int l=0,m=0,h=n-1;
while(m<=h)
{
switch(a[m])
{
case 0:
{
int tmp;
tmp = a[l];
a[l] = a[m];
a[m] = tmp;
l++,m++;
break;
}
case 1:
m++;
break;
case 2:
{
int tmp;
tmp = a[h];
a[h] = a[m];
a[m] = tmp;
h--;
break;
}
}
}
}
int main()
{
fast_io;
if(fopen("C:/Users/Jatin Goel/Desktop/Must-Do-Coding-Questions/input.txt", "r"))
{
freopen("C:/Users/Jatin Goel/Desktop/Must-Do-Coding-Questions/input.txt", "r", stdin);
freopen("C:/Users/Jatin Goel/Desktop/Must-Do-Coding-Questions/output.txt","w",stdout);
}
int n;
cin >> n;
int a[n+5];
for(int i=0;i<n;i++)
cin >> a[i];
sort_012(a,n);
for(int i=0;i<n;i++)
cout << a[i] << " ";
}