public void add(Person p) { //trivial case if (root == null) { root = new Node(p); return; } Node current = root; while (current != null) { if (String.Compare(p.Name,current.person.Name) <= 0) { //if node to the right is empty, the current's left node is instantiated with the new data. //otherwise, current traverses left of the tree. if (current.left == null) { current.left = new Node(p); break; } else current = current.left; } else { if (current.right == null) { current.right = new Node(p); break; } else current = current.right; } } }
public Node(Person p) { person = p; left = right = null; }