public BST find(int v) { if (v == value) { return(this); } else if (v > value) { if (right != null) { return(right.find(v)); } else { return(null); } } else { if (left != null) { return(left.find(v)); } else { return(null); } } }
static void testBST() { BST bst = new BST(10); bst.insert(16); bst.insert(13); bst.insert(12); bst.insert(15); bst.insert(20); bst.insert(18); bst.insert(25); bst.insert(6); bst.insert(3); bst.insert(1); bst.insert(4); bst.insert(8); bst.insert(7); bst.insert(9); bst.insert(14); bst.printInOrder(); int steps = 0;; BST result = bst.find(34, ref steps); if (result == null) { Console.WriteLine("Value not found after {0} steps", steps); } else { Console.WriteLine("Value found after {0} steps", steps); } }