fork download
  1. #include <iostream>
  2. #include <list>
  3. #include <utility>
  4. using namespace std;
  5.  
  6. int main() {
  7. list<int> l({3, 2, 1, 4, 5});
  8. auto it = l.begin(), jt = ++(++l.begin());
  9.  
  10. cout << *it << '\t' << *jt << '\n';
  11. for(int i: l) cout << i << '\t'; cout << '\n';
  12.  
  13. auto hlp = it; ++hlp;
  14. l.splice(jt, l, it);
  15. l.splice(hlp, l, jt);
  16.  
  17. cout << *it << '\t' << *jt << '\n';
  18. for(int i: l) cout << i << '\t'; cout << '\n';
  19.  
  20. return 0;
  21. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
3	1
3	2	1	4	5	
3	1
1	2	3	4	5