forked from sastava007/Tech-Interview-Preparation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSorting Tool.cpp
More file actions
51 lines (46 loc) · 932 Bytes
/
Sorting Tool.cpp
File metadata and controls
51 lines (46 loc) · 932 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
48
49
50
51
#include<bits/stdc++.h>
#define mp make_pair(a,b)
using namespace std;
void swape(long int *x,long int *y)
{
long int temp=*x;
*x=*y;
*y=temp;
}
main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long int n,i,m,j=0;
cin>>n>>m;
long int ele;
vector<long int> fr,el;
for(i=0;i<n;i++)
{
cin>>ele;
vector<long int>::iterator it=find(el.begin(),el.end(),ele);
if(it==el.end())
{
el.push_back(ele);
fr.push_back(1);
}
else
{
fr[it-el.begin()]++;
}
}
//both the vectors will be of same size.
int l=fr.size();
for(i=0;i<l;i++)
{
for(j=0;j<l-i-1;j++)
if(fr[j]<fr[j+1])
{
swape(&el[j],&el[j+1]);
swape(&fr[j],&fr[j+1]);
}
}
for(i=0;i<l;i++)
for(j=0;j<fr[i];j++)
cout<<el[i]<<" ";
}