Question: C++ vector top_n(map &m, int num) top_n: return a vector of the argument map that is sorted in frequency order, highest to lowest. Provide only

C++

vector> top_n(map &m, int num)

top_n: return a vector> of the argument map that is sorted in frequency order, highest to lowest. Provide only the top n values,n provided as an argument. If you sort the vector to find this ordering, than pair_frequency_greaterthan is useful.

It is a two-layered ordering: first by frequency , second alphabetically. Thus you always print the element with the highest frequency. However, if two or more elements are tied in frequency, then print those tied frequency elements in alphabetical order

input:

7 3 5 this thing thin and thick thieves thirst for. 

ouput:

thi:6, hin:2, sth:2, and:1, ckt:1 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!