Advertisement
193030

List example

Apr 8th, 2020
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <list>
  3. #include <iterator>
  4. using namespace std;
  5.  
  6. //function for printing the elements in a list
  7. void showlist(list <int> g)
  8. {
  9.     list <int> :: iterator it;
  10.     for(it = g.begin(); it != g.end(); ++it)
  11.         cout << '\t' << *it;
  12.     cout << '\n';
  13. }
  14.  
  15.  
  16.  
  17.  
  18.  
  19. int main()
  20. {
  21.  
  22.     list <int> gqlist1, gqlist2;
  23.  
  24.  
  25.     for (int i = 0; i < 10; ++i)
  26.     {
  27.         gqlist1.push_back(i * 2);
  28.         gqlist2.push_front(i * 3);
  29.     }
  30.     cout << "\nList 1 (gqlist1) is : ";
  31.     showlist(gqlist1);
  32.  
  33.     cout << "\nList 2 (gqlist2) is : ";
  34.     showlist(gqlist2);
  35.  
  36.     cout << "\ngqlist1.front() : " << gqlist1.front();
  37.     cout << "\ngqlist1.back() : " << gqlist1.back();
  38.  
  39.     cout << "\ngqlist1.pop_front() : ";
  40.     gqlist1.pop_front();
  41.     showlist(gqlist1);
  42.  
  43.     cout << "\ngqlist2.pop_back() : ";
  44.     gqlist2.pop_back();
  45.     showlist(gqlist2);
  46.  
  47.     cout << "\ngqlist1.reverse() : ";
  48.     gqlist1.reverse();
  49.     showlist(gqlist1);
  50.  
  51.     cout << "\ngqlist2.sort(): ";
  52.     gqlist2.sort();
  53.     showList3(gqlist2);
  54.  
  55.     return 0;
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement