![]() |
| ||
| Sorting vectors How do i sort a vector based on the frequency of its elements example my vector contains 10,11,12,10,11,13,11 i need to get the sorted out put as 11,11,11,10,10,12,13 the normal sort is sort(vec.begin(), vec.end()); how do i sort it in that way |
| ||
| Re: Sorting vectors Here is what you are trying to do: http://answers.yahoo.com/question/in...2195554AAANJgl |
| ||
| Re: Sorting vectors What is the ordering? If you want to sort by the most frequent elements first, then you can use the link given to you. If you are sorting by some other rule, you should say what rule that is. |
| ||
| Re: Sorting vectors that link helps but how do i print the elements the the type of output vector in the code below Quote:
|
| ||
| Re: Sorting vectors Won't this be easy, just maintain seperate queue for each element and insert the element into the corresponding queue by dynamic memory allocation, then the queue for which front-reverse is the maximum will have maximum frequency |
| ||
| Re: Sorting vectors Quote:
|
| ||
| Re: Sorting vectors or rather, may be you can use bucket sort, declare a two dimensional array provided you already know the range. just push the number into the corresponding bucket and based on the frequency you can then push it into the stack |
| ||
| Re: Sorting vectors i meant the same for that queue |
| ||
| Re: Sorting vectors Quote:
|
| ||
| Re: Sorting vectors Store the frequencies in a seperate array, sort them and display the contents of the buckets. |
| All times are GMT -4. The time now is 5:50 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC