Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include<iostream>
  2. #include<list>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. list<int> l;
  8. int n = 100;
  9. for(int i = 0; i < n; i++) {
  10. l.push_back(i);
  11. }
  12. list<int>::iterator it = l.end();
  13. it--;
  14. for(; !l.empty(); it--) {
  15. cout << "the size of l is " << (int) l.size() << endl;
  16. l.erase(it);
  17. }
  18. }
  19.  
  20. #include<iostream>
  21. #include<list>
  22.  
  23. using namespace std;
  24.  
  25. int main() {
  26. list<int> l;
  27. int n = 100;
  28. for(int i = 0; i < n; i++) {
  29. l.push_back(i);
  30. }
  31. list<int>::iterator it = l.end();
  32. it--;
  33. for(; !l.empty();) {
  34. cout << "the size of l is " << (int) l.size() << endl;
  35. l.erase(it--);
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement