Java question- Binary Search Tree method?
How do i write a solution to find as well as return number one value, returning null, in the event tree is definitely empty, WITHOUT doing a complete traversal
One on the properties involving BST is the node furthest for the right within the tree is the largest worth.So you would like to start at the root of the particular tree, in the event it’s NULL, returning some meaning saying the particular tree is usually empty.If it’s not at all NULL, then continue advancing towards right infant until people hit NULL, that point the last node was number one item.or maybe in c pseudo computer code
max_element_tree(Tree *root)
if(root == NULL)
returning NULL;
else
Tree *cur = origin;
Tree *next = cur->next;
while(next! = NULL)
cur = up coming;
up coming = cur->next;
returning cur; // pointer towards largest factor in tree
Leave a Reply
You must be logged in to post a comment.