#include <bits/stdc++.h>
#include<map>
using namespace std;
int main()
{ int a[10]={6,8,8,7,7,9,1,1,8,1}; //take user input array of size n
unordered_map<int,int>mp;
priority_queue <pair<int,int>>maxheap;
for(int i=0;i<10;i++)
{
mp[a[i]]++;
}
for(auto it=mp.begin();it!=mp.end();it++)
{
maxheap.push(make_pair(it->second,it->first));
}
while(maxheap.size()>0)
{ int k=maxheap.top().first;
while(k>0)
{
cout<<maxheap.top().second<<endl;
k--;
}
maxheap.pop();
}
return 0;
}
0 Comments