Facebook
From Tom Cruise, 2 Months ago, written in C++.
This paste is a reply to Untitled from Tom Cruise - view diff
Embed
Download Paste or View Raw
Hits: 438
  1. #include <iostream>
  2. #include <iterator>
  3. #include <list>
  4. using namespace std;
  5. void showlist(list<int> g)
  6. {
  7.  list<int>::iterator it;
  8.  for (it = g.begin(); it != g.end(); ++it)
  9.   cout << '\t' << *it;
  10.  cout << '\n';
  11. }
  12. int main()
  13. {
  14.  list<int> list1,list2;
  15.     for (int i = 0; i < 10; ++i) {
  16.   list1.push_back(i * 2);
  17.   list2.push_front(i * 3);
  18.  }
  19.  cout << "\nList 1 (gqlist1) is : ";
  20.  showlist(list1);
  21.  cout << "\nList 2 (gqlist2) is : ";
  22.  showlist(list2);
  23.  cout << "\nlist1.front() : " << list1.front();
  24.  cout << "\nlist1.back() : " << list1.back();
  25.  cout << "\nlist1.pop_front() : ";
  26.  list1.pop_front();
  27.  showlist(list1);
  28.  cout << "\nlist2.pop_back() : ";
  29.  list2.pop_back();
  30.  showlist(list2);
  31.     cout << "\nlist1.reverse() : ";
  32.  list1.reverse();
  33.  showlist(list1);
  34.     cout << "\nlist2.sort(): ";
  35.  list2.sort();
  36.  showlist(list2);
  37.  
  38.  return 0;
  39. }
  40.  
  41.