fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. //Ejemplo 4
  4. int main() {
  5. list <int> lista1;
  6. lista1.push_front(23);
  7. lista1.push_front(45);
  8. lista1.push_front(67);
  9. lista1.push_front(89);
  10. cout << lista1.size() << endl;
  11. list <int> :: iterator it;
  12. it = lista1.begin();
  13. while(it != lista1.end()){
  14. cout << *it << " ";
  15. it++;
  16. }
  17. cout << endl;
  18. it = lista1.end(); it--;
  19. while(it != lista1.begin()){
  20. cout << *it << " ";
  21. it--;
  22. }
  23. cout << *it << endl;
  24. it++;
  25.  
  26. lista1.insert(it, 3, 678);
  27. it = lista1.begin();
  28. while(it != lista1.end()){
  29. cout << *it << " ";
  30. it++;
  31. }
  32. cout << endl;
  33. it--; it--;
  34.  
  35. lista1.erase(it);
  36. it = lista1.begin();
  37. while(it != lista1.end()){
  38. cout << *it << " ";
  39. it++;
  40. }
  41. cout << endl;
  42.  
  43. return 0;
  44. }
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
4
89  67  45  23  
23  45  67  89
89  678  678  678  67  45  23  
89  678  678  678  67  23