-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathsort0s1s2s
More file actions
47 lines (44 loc) · 743 Bytes
/
sort0s1s2s
File metadata and controls
47 lines (44 loc) · 743 Bytes
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
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
void sortArray(int arr[],int n)
{
int low,mid,high;
low=mid=0;
high=n-1;
while(mid<=high)
{
if(arr[mid]==0){
swap(arr[low],arr[mid]);
low++;
mid++;
}
else if(arr[mid]==1)
mid++;
else if(arr[mid]==2){
swap(arr[mid],arr[high]);
high--;
}
}
for(int i=0;i<n;i++)
cout<<arr[i]<<" ";
cout<<"\n";
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
cin>>arr[i];
sortArray(arr,n);
}
return 0;
}