home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / STDLIB.PAK / RNDSHUFL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  771 b   |  32 lines

  1.  #include <algorithm>
  2.  #include <vector>
  3.  
  4.  using namespace std;
  5.  
  6.  int main ()
  7.  {
  8.    //
  9.    // Initialize a vector with an array of integers.
  10.    //
  11.    int arr[10] = {1,2,3,4,5,6,7,8,9,10};
  12.    vector<int> v(arr+0, arr+10);
  13.    //
  14.    // Print out elements in original (sorted) order.
  15.    //
  16.    cout << "Elements before random_shuffle: " << endl << "     ";
  17.    copy(v.begin(), v.end(), ostream_iterator<int>(cout," "));
  18.    cout << endl << endl;
  19.    //
  20.    // Mix them up with random_shuffle.
  21.    //
  22.    random_shuffle(v.begin(), v.end());
  23.    //
  24.    // Print out the mixed up elements.
  25.    //
  26.    cout << "Elements after random_shuffle: " << endl << "     ";
  27.    copy(v.begin(), v.end(), ostream_iterator<int>(cout," "));
  28.    cout << endl;
  29.  
  30.    return 0;
  31.  }
  32.