Advertisement
Guest User

Untitled

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