Retrieving the minimum and maximum key values

Finding out the minimum and maximum key values in a BST is also quite simple. To get a minimum key value, we just need to go to the leftmost node and get the key value. On the contrary, we just need to go to the rightmost node and we will find the maximum key value. The following is the implementation of the FindMin() operation to retrieve the minimum key value, and the FindMax() operation to retrieve the maximum key value:

int BST::FindMin(BSTNode * node){    if(node == NULL)        return -1;    else if(node->Left == NULL)        return node->Key;    else        return FindMin(node->Left);}int BST::FindMax(BSTNode * node){    if(node == NULL)        return -1;    else if(node->Right == NULL)        return node->Key;    else return FindMax(node->Right); ...

Get C++ Data Structures and Algorithms now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.