Advertisement
cd62131

sort random number in C++

Jul 10th, 2014
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iomanip>
  3. #include <iostream>
  4. #include <random>
  5. #include <vector>
  6. using namespace std;
  7. int main() {
  8.   const int DATA_NO = 100;
  9.   vector<int> v;
  10.   random_device rdev;
  11.   mt19937 gen(rdev());
  12.   uniform_int_distribution<> dist(0, 999);
  13.   for (int i = 0; i < DATA_NO; i++)
  14.     v.push_back(dist(gen));
  15.   for (int i = 0; i < DATA_NO; i++) {
  16.     if (i % 10 == 0) cout << endl;
  17.     cout << setw(4) << v[i];
  18.   }
  19.   cout << endl;
  20.   sort(v.begin(), v.end());
  21.   for (int i = 0; i < DATA_NO; i++) {
  22.     if (i % 10 == 0) cout << endl;
  23.     cout << setw(4) << v[i];
  24.   }
  25.   cout << endl;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement