Archived

This topic is now archived and is closed to further replies.

Laroche

Sorting vectors or other containers

Recommended Posts

I have a vector which recieves many insertion and removal requests. The method which uses the vector needs to have it sorted, but I''m not sure exactly how to do this. I''ve looked through SGI documentation of the STL but I have trouble finding exactly what it is I want. Actually, thinking about it, maybe vector is not suited for what I need. I need a container which will sort the objects upon insertion. Which one does this? Unfortunately I dont have any data-structure books at home (its next on my shopping list), so I''m not very knowledgeable in this area.

Share this post


Link to post
Share on other sites
Try these containers:

  std::map
std::priority_queue

The latter seems to fit your description best, but you only ever have access to the first element in the controlled sequence through the "top" member function. It's not too hard to roll your own, less restrictive, priority queue on top of a vector, list or deque.



Edit: stupid smilies.

[edited by - Kippesoep on March 2, 2003 5:16:41 PM]

Share this post


Link to post
Share on other sites