#include <vector> using std::vector; #include <algorithm> using std::random_shuffle; int main() { vector<int> vi; const int MAX = 100; const int WIDTH = 20; for (int i = 0; i < MAX; i++) vi.push_back(i); // Now the vector contains MAX elements: // 0-99 stored in an ascending order for (int i = 0; i < MAX; i++) { cout << vi[i] << ' '; if ( i % WIDTH == WIDTH - 1 ) cout << '\n'; } cout << endl; random_shuffle(vi.begin(), vi.end()); /* shuffle elements */ // display shuffled elements for (int i = 0; i < MAX; i++) { cout << vi[i] << ' '; if ( i%WIDTH == WIDTH-1 ) cout << '\n'; } cout << endl; }
Hosted by www.Geocities.ws

1