Compute Median of Values Stored In Vector - C++?

后端 未结 6 656
故里飘歌
故里飘歌 2020-11-29 03:40

I\'m a programming student, and for a project I\'m working on, on of the things I have to do is compute the median value of a vector of int values. I\'m to do this using onl

6条回答
  •  野性不改
    2020-11-29 04:05

    There is no need to completely sort the vector: std::nth_element can do enough work to put the median in the correct position. See my answer to this question for an example.

    Of course, that doesn't help if your teacher forbids using the right tool for the job.

提交回复
热议问题