Nth_element () function
Header files: #include <algorithm>
Function: Thenth_element function is to find the nth element, and put it in the nth position, subscript is starting from 0 counting, that is, the No. 0 small element is the smallest number.
such as: A[start,end] element interval. After sorting a[n] is the number of n+1 in the series (the subscript starts from 0 count). To be aware of is a[start,n),
The order of size within a[n,end] is not necessarily.
Can only be determined a[n] is the number of n+1 in the series.
Of course a[start,n) in the number certainly not greater than
The number in A[n,end].
Note: the Nth_element () function does not return a value because it is in the position of the nth large number.
The instance code is as follows:
#include <iostream> #include <algorithm>using namespace std; the int main () {int a[]={1,3,4,5,2,6,8,7,9};int i;cout<< "sequence is as follows:" <<endl;for (i=0;i<9;i++) cout< <a[i]<< ""; Nth_element (a,a+5,a+9); cout<<endl<< "The fifth largest number of outputs:" <<a[4]<<endl; Note that the subscript is a return of 0 from the beginning of the 0 count;}
STL's Nth_element () (takes the nth largest value in the container)