Пример #1
0
 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);
         }
     }
 }
Пример #2
0
        private static void BuildBinarySearchTree()
        {
            var bst  = new BinarySearchTree();
            var root = new BstLeaf(10);

            bst.Insert(root, 1);
            bst.Insert(root, 19);

            bst.Traverse(root);
        }
Пример #3
0
        public void Traverse(BstLeaf root)
        {
            if (root == null)
            {
                return;
            }

            Console.WriteLine(root.Key);
            Traverse(root.Left);
            Traverse(root.Right);
        }