Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef struct petaKu
- {
- int position;
- int frequency,num;
- }petaKu;
- void urut( int awal, int akhir, petaKu sb[], int kode)
- {
- //printf("%d%d\n",awal,akhir);
- petaKu temp;
- int i, mot= akhir;
- for(i=awal;i<mot;i++)
- {
- if (mot<0) break;
- if((kode==1 && sb[i].frequency<sb[mot].frequency)
- ||(kode==2 && sb[i].position>sb[mot].position && sb[i].frequency==sb[mot].frequency))
- {
- temp=sb[i];
- sb[i]=sb[mot-1];
- sb[mot-1]=sb[mot];
- sb[mot]=temp;
- i--; mot--;
- //printf("%d%d\n",i,mot);
- }
- }
- // for(i=0;i<akhir;i++)
- // printf("%s\n",sb[i].nama);
- if (mot-1-awal > 0) urut(awal,mot-1,sb,kode);
- if( akhir - (mot+1) > 0) urut(mot+1,akhir, sb,kode);
- }
- int main()
- {
- ios::sync_with_stdio(false);
- int n,k,i,t;
- cin >> n >> k;
- i=n;
- map<int,int> mapKu_freg;
- map<int,int> mapKu_pos;
- /*
- 3 6 6 6 4 4 4 3 3
- freg[3] = 1
- pos[0] = 3
- freg[6] = 3
- pos[1] = 6
- freg[4] = 3
- pos[2] = 4
- */
- int posisi=0;
- while(i--)
- {
- cin >> t;
- if(mapKu_freg.count(t)==0)
- {
- mapKu_freg.insert({t,1});
- mapKu_pos.insert({posisi,t});
- posisi++;
- }else{
- mapKu_freg[t]++;
- }
- }
- petaKu temp[posisi];
- /*
- 3 6 6 6 4 4 4 3 3
- position 0
- temp[0].num = 3
- temp[0].frecun = 3
- */
- for(int j= 0;j<posisi;j++)
- {
- temp[j].position= j;
- temp[j].num = mapKu_pos[j];
- temp[j].frequency = mapKu_freg[temp[j].num];
- }
- urut(0,posisi-1,temp, 1);
- urut(0,posisi-1,temp, 2);
- for(int j= 0;j<posisi;j++)
- {
- for(int k = 0; k < temp[j].frequency;k++)
- {cout << temp[j].num << ' ' ;}
- }
- cout << endl ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement