-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortNumberArrays.cpp
More file actions
executable file
·51 lines (49 loc) · 1.5 KB
/
SortNumberArrays.cpp
File metadata and controls
executable file
·51 lines (49 loc) · 1.5 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
/**
* Answer For
* https://practice.geeksforgeeks.org/problems/sort-an-array-of-0s-1s-and-2s/0
*/
#include <iostream>
using namespace std;
#include <vector>
int main()
{
int testCaseCounter;
cin>>testCaseCounter;
int count=0;
while(count<testCaseCounter){
int arraySize;
cin>>arraySize;
vector<int> arrayx;
int counter=0;
int zeropoint=0;
int onepoint=0;
int twopoint=0;
while(counter<arraySize){
int number;
cin>>number;
if (number==0){
zeropoint++;
}else if (number==1){
onepoint++;
}else if (number==2){
twopoint++;
}
counter++;
}
for(int i=0;i<arraySize;i++){
if(zeropoint-->0)
arrayx.push_back(0);
else if (onepoint-->0){
arrayx.push_back(1);
}else if (twopoint-->0){
arrayx.push_back(2);
}
}
for (int a=0;a<arrayx.size();a++){
cout<<arrayx[a]<<" ";
}
cout<<endl;
count++;
}
return 0;
}