public void Insert(BstLeaf root, int key) { if (key < root.Key) { if (root.Left == null) { root.Left = new BstLeaf(key); } else { root = root.Left; Insert(root, key); } } else { if (root.Right == null) { root.Right = new BstLeaf(key); } else { root = root.Right; Insert(root, key); } } }
private static void BuildBinarySearchTree() { var bst = new BinarySearchTree(); var root = new BstLeaf(10); bst.Insert(root, 1); bst.Insert(root, 19); bst.Traverse(root); }
public void Traverse(BstLeaf root) { if (root == null) { return; } Console.WriteLine(root.Key); Traverse(root.Left); Traverse(root.Right); }