Пример #1
0
        public void Search(int key)
        {
            if (_root == null)
            {
                Console.WriteLine("Tree is empty!");
                return;
            }

            BinaryTreeNode targetNode = _root.Search(key);

            if (targetNode == null)
            {
                Console.WriteLine("Search failed");
                return;
            }

            Console.WriteLine("Value found: " + targetNode.GetValue());
        }
Пример #2
0
        public BinaryTreeNode Search(int key)
        {
            if (key == _key)
            {
                return(this);
            }

            if (key < _key)
            {
                return(_leftChild?.Search(key));
            }

            return(_rightChild?.Search(key));
        }