3 ms·
Er, are you aware of the C++ standard library's std::nth_element() function? (Even my "pure C" programs tend to be compiled with g++ to gain access to that and
by temujin 13y ago
Er, are you aware of the C++ standard library's std::nth_element() function? (Even my "pure C" programs tend to be compiled with g++ to gain access to that and std::sort().)
- nly 13y agoYes, this is exactly what the author is trying to port to Python. Mandatory reference link: http://en.cppreference.com/w/cpp/algorithm/nth_element http://en.cppreference.com/w/cpp/algorithm/nth_element . Note linear complexity. There's also std::partial_sort: http://en.cppreference.com/w/cpp/algorithm/partial_sort http://en.cppreference.com/w/cpp/algorithm/partial_sort