Advertisement
dimon-torchila

Untitled

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