Skip to content

Commit

Permalink
Merge pull request #3 from kingrishabdugar/kingrishabdugar-patch-3
Browse files Browse the repository at this point in the history
Create Count frequencies in unordered Map.cpp
  • Loading branch information
kingrishabdugar authored Oct 1, 2021
2 parents 3a2f0c5 + 0317098 commit be62e79
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Count frequencies in unordered Map.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include<bits/stdc++.h>
using namespace std;
void count_freq(int arr[],int n)
{
unordered_map <int,int> m;
for(int i=0;i<n;i++)
m[arr[i]]++;
for(auto x: m)
cout<<x.first<<" "<<x.second<<endl;
cout<<"In original Order"<<" "<<endl;
for(int i=0;i<n;i++)
{
if(m[arr[i]]!=-1)
cout<<arr[i]<<" "<<m[arr[i]]<<endl;
m[arr[i]]=-1;
}
}
int main()
{
int arr[] = { 10, 20, 20, 10, 10, 20, 5, 20 };
int n = sizeof(arr) / sizeof(arr[0]);
count_freq(arr, n);
return 0;
}

0 comments on commit be62e79

Please sign in to comment.