public int minimum(Bnode node) { if (node == null) { throw new Exception("Tree is empty"); } while (node.left != null) { node = node.left; } return(node.data); }
public int maximum(Bnode node) { if (root == null) { throw new Exception("Tree is empty"); } while (node.right != null) { node = node.right; } return(node.data); }
public Bnode add(int i, Bnode node) { if (node == null) { Bnode newnode = new Bnode(i); node = newnode; return(node); } else if (i > node.data) { node.right = add(i, node.right); return(node); } else { node.left = add(i, node.left); return(node); } }
public void add(int i) { root = add(i, root); }
public BinarySearchTree() { this.root = null; }
public Bnode(int i) { left = null; right = null; data = i; }
public Bnode() { left = null; right = null; }