Question: C++ Using STL Multimap - Help with program I have the following code below using C++ & STL mapcontainers to count the frequency of letters

C++ Using STL Multimap - Help with program

I have the following code below using C++ & STL mapcontainers to count the frequency of letters in a given string(with no spaces). The map data structure stores pairs. In this map,the key is each character, and the value is the frequency.

Need help with: I have the code that retrieves the map valuesand displays to the map, now I need to input the same values into amultimap and output the letters in the order of itsoccurrence(amount of times it is repeated within the string).(arranged from: least # of times --- to greatest # of timesrepeated)

#include #include #include using namespace std;void getFrequency(string strInput,map<char,int> & fMap){    map<char,int>::iterator it; //iterator to find the entries in map    for(int i = 0 ; i < strInput.length() ; i++ )    {        char ch = strInput.at(i);        it = fMap.find(ch); //find the character in the map        if( it == fMap.end() ) //if not present in the map        {            fMap.insert( make_pair(ch,1) );//add an entry        }        else        {            it->second++; //else increment the frequency        }    }}void printFrequency(map<char,int> & fMap){    map<char,int>::iterator it;//iterator to loop through all the chars    for( it = fMap.begin() ; it != fMap.end() ; ++it )    {        cout<<"["<< it->first<<"]"<<"->">strInput;    map<char,int> frequencyMap; //frequency map    getFrequency(strInput, frequencyMap); //get the frequencies    printFrequency(frequencyMap); //print the frequencies}

Step by Step Solution

3.34 Rating (151 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

You can use the STL multimap container to store the same keyvalue pairs from the map but with the ad... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Electrical Engineering Questions!