BinarySearchTree::TreePtr BinarySearchTree::SearchNodeInBST( TreePtr treePtr, DATA_TYPE key ) { if( treePtr != NULL ) { if( key == treePtr->data ) return treePtr; else if( key < treePtr->data ) // Search for "key" in left subtree return SearchNodeInBST( treePtr->leftPtr, key ); else // (key > tree_ptr->data) // Search for "key" in right subtree return SearchNodeInBST( treePtr->rightPtr, key ); } else { return NULL; } }
void BinarySearchTree::SearchNode ( DATA_TYPE searchKey ) { TreePtr srchPtr == NULL; srchPtr = SearchNodeInBST ( rootPtr, searchKey ); if( srchPtr != NULL ) { cout << "\n Node: " << srchPtr->data << " was found in the BST" << endl; } else { cout << "\n Node: " << searchKey << " was not found" << endl; } }