Ejemplo n.º 1
0
Archivo: BST.cs Proyecto: hlimbo/BST
        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;
                }
            }
        }
Ejemplo n.º 2
0
Archivo: Node.cs Proyecto: hlimbo/BST
 public Node(Person p)
 {
     person = p;
     left = right = null;
 }