Let's say I need to retrieve the median from a sequence of 1000000 random numeric values.
If using anything but std::list
, I have no (built-in) way to sort sequence for median calculation.
If using std::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. std::vector
, or is it better to use std::list
and use std::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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…