Feb 11, 2009 at 3:33am
I would like to sort the value that stored in a pair, in descending order(from highest to the lowest). The pair I have defined looks like :
pair<string, double> temp1;
where double stores the frequency of occurrence of the string.
I want to write only top 3 frequencies into a file?
can anybody help?
Last edited on Feb 11, 2009 at 3:35am
Feb 11, 2009 at 6:07am
Just use a vector of pairs, then sort it normally. Then you can just grab the top three out of it.
Feb 11, 2009 at 8:56am
how to use the vectors of pairs ? sorry I am not very good in c++!!
Feb 11, 2009 at 10:24am
How are you storing your pairs?
Feb 12, 2009 at 3:23am
@kbw
I am sorry i did not get your question
Feb 12, 2009 at 8:55am
I take it you have quite a few pairs. Are they being held in an array, in named variables, an STL container, something else?
Why? If they're being held in an STL container, you could define a Less that defines the sort order.