So I have a vector, and I want the elements to be sorted at all times. How should I go about inserting an element into that vector and keeping the elements sorted when I pop them out. I looked into std::lower_bound
, however, that gave the opposite of what I wanted.
For example, this is what I want: When I pop all the elements in the vector it should be:
1 2 3 4 5. That means the vector has to store them as 5 4 3 2 1. If use lower bound, the vector stores them as 1 2 3 4 5, and it is popped as 5 4 3 2 1. Also, a compare functor is going to be passed in so that the lower_bound
function uses the compare functor. Is there a way to take the opposite of a compare functor?
std::set
keeps things sorted, but you can't have duplicates (seestd::multiset
). As for taking the opposite, there'sstd::not1
. – Sexism