private void _insert(int value, Node cur_node) { if (value < cur_node.getValue()) { if (cur_node.getLeftNode() == null) { cur_node.setLeftNode(new Node(value)); } else { this._insert(value, cur_node.getLeftNode()); } } else if (value > cur_node.getValue()) { if (cur_node.getRightNode() == null) { cur_node.setRightNode(new Node(value)); } else { this._insert(value, cur_node.getRightNode()); } } else { Console.WriteLine("Value already exists in tree."); } }
private void _printTree(Node cur_node) { if (cur_node != null) { Console.WriteLine(cur_node.getValue()); _printTree(cur_node.getLeftNode()); _printTree(cur_node.getRightNode()); } }
private bool _search(Node cur_node, int value) { if (cur_node == null) { return(false); } if (cur_node.getValue() == value) { return(true); } else if (value < cur_node.getValue()) { return(this._search(cur_node.getLeftNode(), value)); } else if (value > cur_node.getValue()) { return(this._search(cur_node.getRightNode(), value)); } else { return(false); } }