Dave's Brain

Browse - Programming Tips - Is there a sorted list in the Standard Template Library?

Date: 2015sep9
Language: C++

Q.  Is there a sorted list in the Standard Template Library?

A.  No.  There are some options.

1.  Usually the best way is to use std::set()
It promises to keep everything in order.
Call myset.insert() to add stuff and iterate starting with myset.begin()


2.  You can just do a sort() after each push_back()

list.push_back(n); list.sort();
This is fine for very small lists. 3. You can use sorted_vector<>
http://www.davekb.com/search.php?target=sorted+vector

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.