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