Advertisement
cepxuozab

Tree

Jul 11th, 2023
1,105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.91 KB | None | 0 0
  1.  ( 0 ( -32 ( -48 ( -56 ( -60 ( -62 ( -63 )  ( -61 )  )  ( -58 ( -59 )  ( -57 )  )  )  ( -52 ( -54 ( -55 )  ( -53 )  )  ( -50 ( -51 )  ( -49 )  )  )  )  ( -40 ( -44 ( -46 ( -47 )  ( -45 )  )  ( -42 ( -43 )  ( -41 )  )  )  ( -36 ( -38 ( -39 )  ( -37 )  )  ( -34 ( -35 )  ( -33 )  )  )  )  )  ( -16 ( -24 ( -28 ( -30 ( -31 )  ( -29 )  )  ( -26 ( -27 )  ( -25 )  )  )  ( -20 ( -22 ( -23 )  ( -21 )  )  ( -18 ( -19 )  ( -17 )  )  )  )  ( -8 ( -12 ( -14 ( -15 )  ( -13 )  )  ( -10 ( -11 )  ( -9 )  )  )  ( -4 ( -6 ( -7 )  ( -5 )  )  ( -2 ( -3 )  ( -1 )  )  )  )  )  )  ( 32 ( 16 ( 8 ( 4 ( 2 ( 1 )  ( 3 )  )  ( 6 ( 5 )  ( 7 )  )  )  ( 12 ( 10 ( 9 )  ( 11 )  )  ( 14 ( 13 )  ( 15 )  )  )  )  ( 24 ( 20 ( 18 ( 17 )  ( 19 )  )  ( 22 ( 21 )  ( 23 )  )  )  ( 28 ( 26 ( 25 )  ( 27 )  )  ( 30 ( 29 )  ( 31 )  )  )  )  )  ( 48 ( 40 ( 36 ( 34 ( 33 )  ( 35 )  )  ( 38 ( 37 )  ( 39 )  )  )  ( 44 ( 42 ( 41 )  ( 43 )  )  ( 46 ( 45 )  ( 47 )  )  )  )  ( 56 ( 52 ( 50 ( 49 )  ( 51 )  )  ( 54 ( 53 )  ( 55 )  )  )  ( 60 ( 58 ( 57 )  ( 59 )  )  ( 62 ( 61 )  ( 63 )  )  )  )  )  )  )
  2.  
  3.  
  4. ***
  5.  
  6.  ( 0 ( -32 ( -48 ( -56 ( -60 ( -62 ( -63 )  ( -61 )  )  ( -58 ( -59 )  ( -57 )  )  )  ( -52 ( -54 ( -55 )  ( -53 )  )  ( -50 ( -51 )  ( -49 )  )  )  )  ( -40 ( -44 ( -46 ( -47 )  ( -45 )  )  ( -42 ( -43 )  ( -41 )  )  )  ( -36 ( -38 ( -39 )  ( -37 )  )  ( -34 ( -35 )  ( -33 )  )  )  )  )  ( -16 ( -24 ( -28 ( -30 ( -31 )  ( -29 )  )  ( -26 ( -27 )  ( -25 )  )  )  ( -20 ( -22 ( -23 )  ( -21 )  )  ( -18 ( -19 )  ( -17 )  )  )  )  ( -8 ( -12 ( -14 ( -15 )  ( -13 )  )  ( -10 ( -11 )  ( -9 )  )  )  ( -4 ( -6 ( -7 )  ( -5 )  )  ( -2 ( -3 )  ( -1 )  )  )  )  )  )  ( 32 ( 16 ( 8 ( 4 ( 2 ( 1 )  ( 3 )  )  ( 6 ( 5 )  ( 7 )  )  )  ( 12 ( 10 ( 9 )  ( 11 )  )  ( 14 ( 13 )  ( 15 )  )  )  )  ( 24 ( 20 ( 18 ( 17 )  ( 19 )  )  ( 22 ( 21 )  ( 23 )  )  )  ( 28 ( 26 ( 25 )  ( 27 )  )  ( 30 ( 29 )  ( 31 )  )  )  )  )  ( 48 ( 40 ( 36 ( 34 ( 33 )  ( 35 )  )  ( 38 ( 37 )  ( 39 )  )  )  ( 44 ( 42 ( 41 )  ( 43 )  )  ( 46 ( 45 )  ( 47 )  )  )  )  ( 56 ( 52 ( 50 ( 49 )  ( 51 )  )  ( 54 ( 53 )  ( 55 )  )  )  ( 60 ( 58 ( 57 )  ( 59 )  )  ( 62 ( 61 )  ( 63 )  )  )  )  )  )  )
  7.  
  8.  
  9. ***
  10.  
  11. TreeNode<int>* MakeTree(int value, TreeNode<int>* parent, int depth, int max_depth) {
  12.         auto new_node = new TreeNode<int>{value, parent, nullptr, nullptr};
  13.         if (depth <= max_depth) {
  14.             new_node->left = MakeTree(value - (1<<(max_depth - depth)), new_node, depth + 1, max_depth);
  15.             new_node->right = MakeTree(value + (1<<(max_depth - depth)), new_node, depth + 1, max_depth);
  16.         }
  17.         return new_node;
  18.     }
  19. int main() {
  20.     using namespace std;
  21.         using T = TreeNode<int>;
  22.  
  23.         T* root = MakeTree(0, nullptr, 0, 5);
  24.         cout << root << endl;
  25.  
  26.         T* iter = begin(root);
  27.  
  28.         while (iter) {
  29.             iter = next(iter);
  30.         }
  31. cout<<"\n\n***\n\n";
  32.         cout << root << endl;
  33.         cout<<"\n\n***\n\n";
  34.         DeleteTree(root);    
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement