What is the right approach when using STL container for median calculation?
- by sharkin
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?