Example #1
0
 /// <summary>
 /// Insert a node into the data tree
 /// </summary>
 /// <param name="person">New Person object</param>
 public void Insert(Person person)
 {
     Node insertNode = new Node(person);
     if (root == null)
     {
         root = insertNode;
     }
     else
     {
         Insert(insertNode, ref root);
     }
     count++;
 }
Example #2
0
 private Node Insert(Node insertNode, ref Node tree)
 {
     if (tree == null)
     {
         tree = insertNode;
     }
     else
     {
         int compare = tree.Value.CompareTo(insertNode.Value);
         if (compare < 0)
         {
             Insert(insertNode, ref tree.LeftNode);
         }
         else if (compare > 0)
         {
             Insert(insertNode, ref tree.RightNode);
         }
         else
         {
             throw new Exception("Duplicate entry, insert aborted");
         }
     }
     return insertNode;
 }
Example #3
0
 public Node(Person person)
 {
     RightNode = null;
     LeftNode = null;
     Value = person;
 }