Skip to content

Commit

Permalink
Merge pull request #2735 from priyanshu-28/priyanshu-28-patch-1
Browse files Browse the repository at this point in the history
Create Count frequency of elements.cpp
  • Loading branch information
ZoranPandovski authored Oct 1, 2021
2 parents 5941385 + 45d3e91 commit 877f67b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions data_structures/hash_map/CPP/Count frequency of elements.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include<bits/stdc++.h>
using namespace std;

int main()
{
int arr[6] = {1,2,2,1,3,4}; // Here 1 is 2 times, 2 is 2 times and 3 and 4 is 1 time
map<int,int> m;
for(int i=0;i<6;i++){
m[arr[i]]++; // Stores the frequency for each element
}
for(auto [x,y]:m){
cout<<"Element: "<<x<<" "<< "Frequency: "<<y<<endl;
}

return 0;
}

0 comments on commit 877f67b

Please sign in to comment.