std::set
is a sorted tree. It provides begin
and end
methods so I can get minimum and maximum and lower_bound
and upper_bound
for binary search. But what if I want to get iterator pointing to the middle element (or one of them if there are even number of elements there)?
Is there an efficient way (O(log(size))
not O(size)
) to do that?
{1} => 1
{1,2} => 1 or 2
{1,2,3} => 2
{1,2,3,4} => 2 or 3 (but in the same direction from middle as for {1,2})
{1,312,10000,14000,152333} => 10000