public void insert(int input) { depth = 0; if (Head == null) { Head = new Tree_Node(input); } else { insert_helper(input, Head); } print(); }
private bool search_helper(int test, Tree_Node root) { if (root == null) { return false; } if (root.Value == test) { return true; } else if (test >= root.Value) { return search_helper(test, root.Right); } else { return search_helper(test, root.Left); } }
private void insert_helper(int input, Tree_Node root) { if (input >= root.Value) { if (root.Right == null) { nodes++; root.Right = new Tree_Node(input); } else { insert_helper(input, root.Right); } } else if (input < root.Value) { if (root.Left == null) { nodes++; root.Left = new Tree_Node(input); } else { insert_helper(input, root.Left); } } }
public Tree_Node(int input) { Value = input; Left = null; Right = null; }
public Binary_Search_Tree() { Head = null; depth = 0; nodes = 0; }