Advertisement
dimon-torchila

Untitled

Jan 5th, 2023
920
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2.  
  3. using namespace std;
  4.  
  5. namespace lab3{
  6.     struct TreeNode {
  7.         int val;
  8.         vector<TreeNode*> childs;
  9.         TreeNode() : val(0) { childs.push_back(nullptr); childs.push_back(nullptr);}
  10.         TreeNode(int x) : val(x)  { childs.push_back(nullptr); childs.push_back(nullptr);}
  11.     };
  12.     void Add(TreeNode *&tree, int x) {
  13.         if (tree == nullptr)
  14.             tree = new TreeNode(x);
  15.         else
  16.         if (tree->val < x)
  17.             Add(tree->childs[0], x);
  18.         else
  19.             Add(tree->childs[1], x);
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement