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()); }
public BinaryTreeNode Search(int key) { if (key == _key) { return(this); } if (key < _key) { return(_leftChild?.Search(key)); } return(_rightChild?.Search(key)); }