Exemplo n.º 1
0
 //���ֱ������ķ�ʽ
 /// <summary>
 /// �������
 /// </summary>
 /// <param name="theRoot"></param>
 public void InOrder(Node theRoot)
 {
     if (theRoot !=null)
     {
         InOrder(theRoot.Left);
         theRoot.DisplayNode();
         InOrder(theRoot.Right);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// �����½��
 /// </summary>
 /// <param name="i"></param>
 public void Insert(int i)
 {
     Node newNode = new Node();
     newNode.Data = i;
     if (root == null)
     {
         root = newNode;
     }
     else
     {
         Node current = root;
         Node parent = new Node();
         while (true)
         {
             parent = current;
             if (i < parent.Data)
             {
                 current = current.Left;
                 if (current == null)
                 {
                     parent.Left = newNode;
                     break;
                 }
             }
             else
             {
                 current = current.Right;
                 if (current == null)
                 {
                     parent.Right = newNode;
                     break;
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 public BinarySearchTree()
 {
     root = null;
 }
Exemplo n.º 4
0
 /// <summary>
 /// �������
 /// </summary>
 /// <param name="theRoot"></param>
 public void PreOrder(Node theRoot)
 {
     if (theRoot != null)
     {
         theRoot.DisplayNode();
         PreOrder(theRoot.Left);
         PreOrder(theRoot.Right);
     }
 }