既然是排序,就先找点需要排序的数据吧,用c自带的库函数生成一些随机数
先以能用为目标,回头进行改进
- ///
- //生成一个随机数文件
- ///
- #include<iostream>
- #include<cstdlib>
- #include<fstream>
- using namespace std;
- int main()
- {
- int size, max;
- ofstream output("data.txt");
- cout<<"请输入随机数规模大小:"<<endl;
- cin>>size;
- cout<<"你选择生成大小为"<<size<<"的随机数序列"<<endl;
- cout<<"请输入最大随机数"<<endl;
- cin>>max;
- cout<<"你选择生成个数为"<<size<<",最大为"<<max<<"的随机数序列"<<endl;
- srand(time(NULL));
- for(int i = 0; i < size; i++)
- {
- output<<(rand()%max)<<endl;
- }
- cout<<"生成成功data.txt"<<endl;
- output.close();
- return 0;
- }