fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int f;
  5.  
  6. void LNR(int n)
  7. {
  8. if(2 * n >= pow(2, f) - 1){
  9. cout << n << " ";
  10. return;
  11. }
  12. LNR(2 * n);
  13. cout << n << " ";
  14. LNR(2 * n + 1);
  15. }
  16.  
  17. void NLR(int n)
  18. {
  19. cout << n << " ";
  20. if(2 * n >= pow(2, f)){
  21. return;
  22. }
  23. NLR(2 * n);
  24. NLR(2 * n + 1);
  25. }
  26.  
  27. void LRN(int n)
  28. {
  29. if(n >= pow(2, f)) return;
  30. LRN(2 * n);
  31. LRN(2 * n + 1);
  32. cout << n << " ";
  33. }
  34. int main()
  35. {
  36. ios_base::sync_with_stdio(0);
  37. cin.tie(0);
  38. cout.tie(0);
  39. cin >> f;
  40. LNR(1);
  41. cout << "\n";
  42. NLR(1);
  43. cout << "\n";
  44. LRN(1);
  45. }
  46.  
Success #stdin #stdout 0.01s 5312KB
stdin
Standard input is empty
stdout
1 
1