| | |
sorting stl::map
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Does anyone know of a good way to sort an stl map?
I have something like the following example:
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
I have something like the following example:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <map> #include <algorithm> int main() { map<int, float> map_to_sort; // Populate the map with between 20 - 2000 elements map_to_sort.sort(); }
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
"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
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
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
![]() |
Similar Threads
- Deallocating memory used by a STL map (C++)
- 2gb stl map performance (C++)
- Code Snippet: Populate an STL map with two arrays (C++) (C++)
- Code Snippet: Using STL map for elements(Chem.) (C++)
- STL <map> question? (C++)
Other Threads in the C++ Forum
- Previous Thread: New to C++, need help
- Next Thread: Is c # slower than c/c++
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion count database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive return sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






