fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8. int n;
  9. cin>>n;
  10.  
  11. queue<int> q;
  12. for(int i=1;i<=n;i++)
  13. {
  14. q.push(i);
  15. }
  16.  
  17. bool flag=false;
  18. while(!q.empty())
  19. {
  20. int val = q.front();
  21. q.pop();
  22.  
  23. if(flag == true)
  24. {
  25. cout<<val<<" ";
  26. }
  27. else
  28. {
  29. q.push(val);
  30. }
  31. flag=!flag;
  32. }
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 5244KB
stdin
7
stdout
2 4 6 1 5 3 7