fork download
  1. #include <iostream>
  2. #include <list>
  3.  
  4. using namespace std;
  5.  
  6. void rev(list<int>& l, int pb, int pe)
  7. {
  8. list<int> tmp;
  9. auto b = l.begin();
  10. tmp.splice(tmp.end(),l,next(b,pb),next(b,pe+1));
  11. tmp.reverse();
  12. l.splice(next(b,pb),tmp);
  13. }
  14.  
  15. int main(int argc, char * argv[])
  16. {
  17. list<int> l = {0,1,2,3,4,5,6,7,8,9};
  18.  
  19. for(auto i: l) cout << i << " "; cout << endl;
  20. rev(l,4,6);
  21. for(auto i: l) cout << i << " "; cout << endl;
  22.  
  23. }
  24.  
  25.  
Success #stdin #stdout 0.01s 5504KB
stdin
Standard input is empty
stdout
0  1  2  3  4  5  6  7  8  9  
0  1  2  3  6  5  4  7  8  9