10_33.cpp

来自「c++案例教程源代码」· C++ 代码 · 共 18 行

CPP
18
字号
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{	int Array[9]={25,7,9,2,0,5,21,15,13};
	vector<int> iVector(Array,Array+9);
	//使用通用算法nth_element将第N个最小元素放置在v.begin() + N
	nth_element(iVector.begin(),iVector.begin() + 3, iVector.end());
	cout << "After nth_element:  ";
	copy(iVector.begin(), iVector.end(), ostream_iterator<int> (cout, " "));
	//使用通用算法random_shuffle混排元素
	random_shuffle(iVector.begin(),iVector.end());
	cout << "\nAfter random_shuffle:  ";
	copy(iVector.begin(), iVector.end(), ostream_iterator<int> (cout, " "));
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?