Nth_element () function
Header files: #include <algorithm>
Function: Thenth_element function is to find the nth element, and put it in the nth position, the subscript is counted from 0, 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 (subscript starting from 0 counts). 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 simply rows the number of the nth large and does not return a value.
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 the return 0 counted from 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
STL's Nth_element () (takes the nth largest value in the container)