fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int max_size = 14;
  5. void traversal(int x, int depth){
  6. if(x > max_size) return;
  7. cout << setw(depth * 2) << x << endl;
  8. traversal(x * 2 + 1, depth + 1);
  9. traversal(x * 2 + 2, depth + 1);
  10. }
  11.  
  12. int main(){
  13. traversal(0, 0);
  14. }
Success #stdin #stdout 0.01s 5260KB
stdin
Standard input is empty
stdout
0
 1
   3
     7
     8
   4
     9
    10
 2
   5
    11
    12
   6
    13
    14