What is the right approach when using STL container for median calculation?
Posted
by sharkin
on Stack Overflow
See other posts from Stack Overflow
or by sharkin
Published on 2009-11-12T00:32:32Z
Indexed on
2010/04/05
16:03 UTC
Read the original article
Hit count: 342
Let's say I need to retrieve the median from a sequence of 1000000 random numeric values.
If using anything but STL::list, I have no (built-in) way to sort sequence for median calculation.
If using STL::list, I can't randomly access values to retrieve middle (median) of sorted sequence.
Is it better to implement sorting myself and go with e.g. STL::vector, or is it better to use STL::list and use STL::list::iterator to for-loop-walk to the median value? The latter seems less overheadish, but also feels more ugly..
Or are there more and better alternatives for me?
© Stack Overflow or respective owner