fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. enum shift_dir { POSITIVE = 1, NEGATIVE = -1 };
  6.  
  7. int main() {
  8.  
  9. int index = 0;
  10. vector<int> v = {1,2,3,4};
  11.  
  12. auto dir = shift_dir::NEGATIVE;
  13.  
  14. index = (index + dir) % v.size();
  15. cout << index << endl;
  16.  
  17. index = (index + dir) % v.size();
  18. cout << index << endl;
  19.  
  20. index = (index + dir) % v.size();
  21. cout << index << endl;
  22.  
  23. index = (index + dir) % v.size();
  24. cout << index << endl;
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
3
2
1
0