/// <summary> /// Printing inorder traversal /// <param name="n">Node to be the root /// </summary> internal void InorderPrint(BstNode n) { if (n != null) { InorderPrint(n.Left); Console.WriteLine("{0}->", n.Data); InorderPrint(n.Right); } }
/// <summary> /// Inserting node in BST /// <param name="d"> Data element in node </param> /// </summary> public void InsertNode(int d) { BstNode newBstNode = new BstNode(d); if (root == null) { root = newBstNode; } else { BstNode temp = root; while (temp != null) { if (d < (int)temp.Data) { if (temp.Left == null) { temp.Left = newBstNode; break; } else { temp = temp.Left; } } else { if (temp.Right == null) { temp.Right = newBstNode; break; } else { temp = temp.Right; } } } } }
/// <summary> /// Constructor initializing an empty binary search tree /// </summary> public BinarySearchTree() { root = null; }
/// <summary> /// Constructor initializing a new node /// </summary> public BstNode(object d) { data = d; right = null; left = null; }
/// <summary> /// Constructor initializing root to null /// </summary> public HeightBalancedBst(int s) { root = null; size = s; sortedArray = new int[size]; }