排序算法random_shuffle洗牌算法
作者:互联网
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Print
{
public:
void operator()(int i)
{
cout << i << endl;
}
};
int main()
{
srand(time(NULL));
vector<int> v;
for(int i = 0; i < 10; i++)
{
v.push_back(i);
}
random_shuffle(v.begin(), v.end());
for_each(v.begin(), v.end(), Print());
return 0;
}
注:使用时,记得加随机数种子
标签:shuffle,int,random,算法,Print,end,include 来源: https://www.cnblogs.com/zhangxuechao/p/16537285.html