1public static Node insert(Node root, int x){
2 if (root == null)
3 return new Node(x);
4 else if(x>root.getData())
5 root.setRightChild(insert(root.getRightChild(),x));
6 else
7 root.setLeftChild(insert(root.getLeftChild(),x));
8 return root;
9}
10
1void BSNode::insert(std::string value) {
2
3 if (this->_data == value) {
4 _count++;
5 return;
6 }
7
8 if (this->_data > value) {
9 if (this->getLeft() == nullptr) {
10 this->_left = new BSNode(value);
11 }
12 this->getLeft()->insert(value);
13 return;
14 }
15
16 if (this->getRight() == nullptr) {
17 this->_right = new BSNode(value);
18 return;
19 }
20 this->getRight()->insert(value);
21}