C++ Standard Library nth_element() Sample

Description

nth_element() sorts only as necessary in order to get the Nth element of a sequence into its proper position. No element comparing less than the Nth one will be placed after it in the sequence. This is useful in computing medians, percentiles, and so on.

Declaration

	template <class Ran>
	    void nth_element(Ran, Ran, Ran);
	template <class Ran, class Cmp>
	    void nth_element(Ran, Ran, Ran, Cmp);

Concept

The sample program establishes a vector, and then computes the value of the median element, which is displayed (18).

Supported
Supported
Supported