当前位置:   article > 正文

C/C++中nth_element函数(第k小 STL)_c nthemelent

c nthemelent

例子:六个数中的第五大的数(第五大, 因为数组从0-5, 第0大就是最小值)

#include <bits/stdc++.h>
using namespace std;
int main()
{
	vector<int> arr(6,0);
    for (int i = 0; i < 6; i++) cin >> sz[i];
    nth_element(arr.begin(), arr.begin() + 5, arr.end());
    cout << arr[5];
    return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/315684?site
推荐阅读