问题及代码:
/*Copyright (c)2016,烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:main.cpp
*作 者:崔青青
*完成日期:2016年6月3日
*版 本 号:v1.0
*问题描述:
*输入描述:无
*输出描述:无
*/
#include <ctime>
#include <vector>
#include <list>
#include <iostream>
#include <iterator>
#include <cstdlib>
using namespace std;
using namespace std;
typedef vector<int> IntVector;
typedef unsigned int VIndex;
void vectorShuffle(IntVector &unshuffled,IntVector &shuffled)
{
VIndex p,size=unshuffled.size();
while(size)
{
p=rand()%size--;
shuffled.push_back(unshuffled[p]);
unshuffled.erase(unshuffled.begin()+p);
}
}
int main()
{
ostream_iterator<int> os(cout," ");
srand(time(NULL));
IntVector c,sc;
for(VIndex i=1; i<=54; i++)
{
c.push_back(i);
}
cout<<"Before Shuffle"<<endl;
copy(c.begin(),c.end(),os);
cout<<endl;
vectorShuffle(c,sc);
cout<<"\nAfter Shuffled"<<endl;
copy(sc.begin(),sc.end(),os);
cout<<endl<<endl;
return 0;
}
运行结果:
知识点总结:
用vector动态数组做。
学习心得:
这样的程序需要好好查一下资料才能真正弄懂,加油。