What is the right approach when using STL container for median calculation?

后端 未结 10 952
再見小時候
再見小時候 2020-12-02 10:17

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 (

10条回答
  •  误落风尘
    2020-12-02 11:04

    You can sort an std::vector using the library function std::sort.

    std::vector vec;
    // ... fill vector with stuff
    std::sort(vec.begin(), vec.end());
    

提交回复
热议问题