//���ֱ������ķ�ʽ /// <summary> /// ������� /// </summary> /// <param name="theRoot"></param> public void InOrder(Node theRoot) { if (theRoot !=null) { InOrder(theRoot.Left); theRoot.DisplayNode(); InOrder(theRoot.Right); } }
/// <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; } } } } }
public BinarySearchTree() { root = null; }
/// <summary> /// ������� /// </summary> /// <param name="theRoot"></param> public void PreOrder(Node theRoot) { if (theRoot != null) { theRoot.DisplayNode(); PreOrder(theRoot.Left); PreOrder(theRoot.Right); } }