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