3,881
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int a[] = {9, 1, 5, 4, 2, 3, 7, 4, 2, 6, 8, 3, 7};
nth_element(a, a + (sizeof(a) / sizeof(a[0]) / 2 - 1), a + sizeof(a) / sizeof(a[0] / 2));
cout<<*(a + (sizeof(a) / sizeof(a[0]) / 2 - 1))<<endl;
return 0;
}
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int a[] = {9, 1, 5, 4, 2, 3, 7, 4, 2, 6, 8, 3, 7};
int *result = nth_element(a, a + (sizeof(a) / sizeof(a[0]) / 2 - 1), a + sizeof(a) / sizeof(a[0] / 2);
return 0;
}