The minimum value of a binary tree question



At the following url...
http://cslibrary.stanford.edu/110/BinaryTrees.html

They have the following as a solution to finding the min value of a
binary tree...
4. minValue() Solution (C/C++)
/*
Given a non-empty binary search tree,
return the minimum data value found in that tree.
Note that the entire tree does not need to be searched.
*/
int minValue(struct node* node) {
struct node* current = node;

// loop down to find the leftmost leaf
while (current->left != NULL) {
current = current->left;
}

return(current->data);
}

Why do they do 'current->left != NULL' in the while loop instead of
something like 'current != NULL'? Ie, something like the
following....

int minValue(struct node* node) {
struct node* current = node;

// loop down to find the leftmost leaf
while (current != NULL) {
current = current->left;
}

return(current->data);
}
.



Relevant Pages

  • Re: NEED HELP WITH A PROGRAM....ANYONE PLEASE HELP!
    ... struct Node* left_child; ... if done exit the loop ... add the word to the tree -- a function you write. ... how to display it's content. ...
    (comp.lang.c)
  • Re: The minimum value of a binary tree question
    ... return the minimum data value found in that tree. ... struct node* current = node; ... // loop down to find the leftmost leaf ...
    (comp.programming)
  • Re: Is There a Java Class for this Kind of Data Structure?
    ... They can be affected by uncles/aunts, but NOT by siblings. ... I was looking into a tree because I thought that would be the easiest way to ... who in turn notify their dependents and so on. ... Right now I'm experimenting with a loop that I wouldn't actually label as ...
    (comp.lang.java.programmer)
  • Looping Through All Nodes In A VB.NET Tree View And Highlighting Them.
    ... highlight them as the loop is active. ... I have a function in my application that builds a tree view. ... populates the tree view with parent nodes. ... I now have a tree view with parent and children nodes. ...
    (microsoft.public.dotnet.languages.vb.controls)
  • Re: Need some light on using Ada or not
    ... As this is my first experiment with tasking, comments are welcome (and I'd be ... there said that we couldn't use arrays as binary-trees. ... -- If it is a large enough tree, ... For Index in Internal_Nodes Loop ...
    (comp.lang.ada)