Jump to content
  • Advertisement

Archived

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

mrmrcoleman

STL Question.

This topic is 5392 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In a program I am working on I need to be able to maintain a list of objects. i.e. to be able to add, remove, and sort them. I have read that the standard template library can do this for me but I am a bit lost when it comes to sorting the lists. I have done something similar to this is Java whereby you just make sure that the objects in the list have a comparison method implemented and then the container does the rest, but this doesnt seem to be the case with STL? Could anybody give me a brief introduction in plain english so that I can get my head round this?? Thank you for any help. Mark Coleman

Share this post


Link to post
Share on other sites
Advertisement
Also, if the sorting is a very important or frequently needed aspect (like if you''re doing lots of dynamic object additions), you could put them into a std::set, which DOES automatically sort them by storing them in a binary search tree (usually a red-black tree).

Share this post


Link to post
Share on other sites
sort() is a member function of std::list. Some compilers ship with broken copies of std::list::sort(), however. std::sort() sorts a range defined by random acess iterators, so can only be used with certain containers such as std::vector or std::deque (not std::list).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
A std::map is also always sorted.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!