64,646
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#define N 10
using namespace std;
int main(int argc, char* argv[])
{
vector<int> v;
srand(time(NULL));
int t,max;
for (int i=0; i<1000000; i++) {
v.push_back(rand());//生成随机数
//cout << v[i] << ' ';
}
//cout << endl;
for (int k=0; k<N; k++) {//冒N次泡就行了。
for (int j=0; j<1000000-1; j++) {
if (v[j]>v[j+1]) {
t=v[j];
v[j]=v[j+1];
v[j+1]=t;
}
}
}
for (int l=1000000-N; l<1000000; l++)
cout << v[l] << ' ';
cout << endl;
return 0;
}