//排序规则采用默认的升序排序
void nth_element (RandomAccessIterator first,
RandomAccessIterator nth,
RandomAccessIterator last);
//排序规则为自定义的 comp 排序规则
void nth_element (RandomAccessIterator first,
RandomAccessIterator nth,
RandomAccessIterator last,
Compare comp);
std::vector<int> v {5, 10, 6, 4, 3, 2, 6, 7, 9, 3}; //10个元素
auto m = v.begin() + v.size() / 2; //中间
std::nth_element(v.begin(), m, v.end());
std::cout << "\nThe median is " << v[v.size() / 2] << '\n';
//[输出]
//The median is 6
//v = {3, 2, 3, 4, 5, 6, 10, 7, 9, 6};