mickypinata

SMMR-T022: Preorder

Jun 1st, 2021 (edited)
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void preOrder(int x, int n){
  5.     if(x > n){
  6.         return;
  7.     }
  8.     cout << x << ' ';
  9.     preOrder(x << 1, n);
  10.     preOrder(x << 1 | 1, n);
  11. }
  12.  
  13. int main(){
  14.  
  15.     int Q;
  16.     scanf("%d", &Q);
  17.     for(int q = 1; q <= Q; ++q){
  18.         int n;
  19.         scanf("%d", &n);
  20.         cout << "Case #" << q << ": ";
  21.         preOrder(1, n);
  22.         cout << '\n';
  23.     }
  24.  
  25.     return 0;
  26. }
  27.  
Add Comment
Please, Sign In to add comment