Map in c++ are the containers that stores elements in the form of keys and values in a mapped format. You can use map for solving various problems,like if you want to calculate any element's frequency. Syntax for map in c++: map<type,type> name_of_map; For ex: map<int,int>m1; where,key type is integer value type is integer name of map is 'm1' Header file Header file of map in c++ is #include<map>. Program for counting frequency of elements: #include<iostream> #include<map> using namespace std; int main() { int a[]={1,2,4,19,10,23,1,1,2,4,23,4,4,19}; map<int,int>m1; for(int i=0;i<14;i++) { m1[a[i]]++; //counting elements } cout<<"Frequency of 1 is :"<<m1[1]<<endl; cout<<"Frequency ...
Comments
Post a Comment