sorting stl::map

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2004
Posts: 113
Reputation: liliafan is on a distinguished road 
Solved Threads: 2
liliafan's Avatar
liliafan liliafan is offline Offline
Junior Poster

sorting stl::map

 
1
  #1
Aug 20th, 2004
Does anyone know of a good way to sort an stl map?

I have something like the following example:

  1. #include <iostream>
  2. #include <map>
  3. #include <algorithm>
  4.  
  5. int main()
  6. {
  7. map<int, float> map_to_sort;
  8.  
  9. // Populate the map with between 20 - 2000 elements
  10.  
  11. map_to_sort.sort();
  12. }

Obviously I am aware that map<> doesn't have a sort function :op so does anyone have a quick method of sorting through a map?

From the best I can see I am going to have to manually iterate through all elements of the map and compare and move to a seperate map, I am hoping there is a better solution than this since that seems like a wasteful use of CPU time, this is for a searchengine project I am working on and as can be expected time is critical in this application, especially considering I actually need to sort through 3 seperate maps.

Any help would be really appreciated.

Best regards

Ben
Application development, webhosting, and much more: www.webcentric-hosting.com
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,341
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: sorting stl::map

 
0
  #2
Aug 20th, 2004
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 113
Reputation: liliafan is on a distinguished road 
Solved Threads: 2
liliafan's Avatar
liliafan liliafan is offline Offline
Junior Poster

Re: sorting stl::map

 
0
  #3
Aug 21st, 2004
Hi Dave

I kinda figured there wasn't a sort() algorithm on map<> but I was hoping that maybe someone had written some efficient code to do a sort, and if so if they could give a few pointers on how it is achieved.

Thanks

Ben
Application development, webhosting, and much more: www.webcentric-hosting.com
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC