Advertisement
Guest User

LList

a guest
Nov 13th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <list>
  2. #include <iostream>
  3. #include <iterator>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     list<int> l = { 4, 7, 8, 1, 3 };
  10.     int n = l.size();
  11.     int i = 0;
  12.     list<int>::iterator it = l.begin();
  13.     while (it != l.end())
  14.     {
  15.         if (*it == n - i - 1)
  16.         {
  17.             it = l.erase(it);
  18.         }
  19.         else
  20.         {
  21.             ++it;
  22.         }
  23.         ++i;
  24.     }
  25.     it = l.begin();
  26.     while (it != l.end())
  27.     {
  28.         cout << *it << ' ';
  29.         ++it;
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement