Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <time.h>
  4. #include <list>
  5. #include <iterator>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     //STL list container
  11.     list<int> intList;
  12.     //STL list container iterator
  13.     list<int>::iterator it;
  14.     //Seed random generator
  15.     srand((unsigned)time(NULL));
  16.  
  17.     //Insert 10 random items into the list container
  18.     for(int i = 0; i < 10; i++)
  19.         intList.insert(++intList.begin(),(rand() % 200 + 1));
  20.  
  21.     //Print container
  22.     cout << "10 random items in the list container" << endl;
  23.     for(it = intList.begin(); it != intList.end(); ++it)
  24.         cout << (*it) << " ";
  25.     cout << endl;
  26.  
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement