voidnth_element(RandomIt first, RandomIt nth, RandomIt last); (1)(constexpr since C++20) template<classExecutionPolicy,classRandomIt> voidnth_element(ExecutionPolicy&&policy, RandomIt first, RandomIt nth, RandomIt last); (2)(since C++17) ...
可能的实现 参阅libstdc++与libc++中的实现。 示例 运行此代码 #include <iostream>#include <vector>#include <algorithm>#include <functional>intmain(){std::vector<int>v{5,6,4,3,2,6,7,9,3};std::nth_element(v.begin(), v.begin()+v.size()/2, v.end());std::cout<<"The median is ...