-
Notifications
You must be signed in to change notification settings - Fork 0
/
frquencysorting.cpp
55 lines (55 loc) · 934 Bytes
/
frquencysorting.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
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t,i,n,max,index;
cin>>t;
while(t--)
{
int a[1001],b[65];
for(i=0;i<=65;i++)
{
a[i] =0 ;
}
cin>>n;
for(i=0;i<n;i++)
{
cin>>a[i];
b[a[i]]++;
}
max= 0 ;
int l =0 ;
for(i=0;i<=65;i++)
{
if(b[i]!=0)
l++;
}
int k;
while(l!=0)
{
for(i=0;i<=65;i++)
{
if(max<b[i])
{
max = b[i];
index = i;
}
}
l--;
if(b[index]>1)
{
k = b[index];
while(k>0)
{cout<<index<<" ";
k--;
b[index]--;}
}
if(b[index]==1)
{cout<<index<<" ";}
max =0;
b[index]=0;
}
cout<<"\n";
}
return 0;
}