#include<iostream> #include<algorithm> using namespace std; int main() { int array[] = {5,6,7,8,4,2,1,3,0}; int len=sizeof(array)/sizeof(int); cout<<"排序前: "; for(int i=0; i<len; i++) cout<<array[i]<<" "; nth_element(array, array+6, array+len); //排序第6个元素 cout<<endl; cout<<"排序后:"; for(int i=0; i<len; i++) cout<<array[i]<<" "; cout<<endl<<"第6个元素为"<<array[6]<<endl; }