Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <list>
- #include <iostream>
- #include <iterator>
- using namespace std;
- int main()
- {
- list<int> l = { 4, 7, 8, 1, 3 };
- int n = l.size();
- int i = 0;
- list<int>::iterator it = l.begin();
- while (it != l.end())
- {
- if (*it == n - i - 1)
- {
- it = l.erase(it);
- }
- else
- {
- ++it;
- }
- ++i;
- }
- it = l.begin();
- while (it != l.end())
- {
- cout << *it << ' ';
- ++it;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement