Sunday, Nov 18th

Last update12:59:40 PM GMT

Write a C program to find the mininum value in a binary search tree.

Write e-mail
As per the definition of binary search tree, there is root node such that left node to it has all values smaller than root node value and right node has values larger than root node value. And it follows for all nodes.
So, if we traverse the left node till the left node is null, we will get the smallest value.
int minValue(struct node* node) 
{ 
 struct node* current = node; 

 while (current->left != NULL) 
 { 
 current = current->left; 
 }
 
 return(current->data); 
}
Similarly, if we keep traversing the right nodes, we will get the largest value.

Share this post



Web Hosting