Jul 302012

Earlier, we have seen how to find the minimum element in a Binary Search Tree.

Write a function which will return the maximum value in a binary search tree. For example: For the below Binary search tree, the function should return 40

Structure of the Node of the Tree is as given below:

    struct Node
        int data;
        Node* lptr; // Ptr to LEFT subtree
        Node* rptr; // ptr to RIGHT subtree


Function to get the maximum element in the tree will also be similar:

    int getMaximum(Node* root)
        while(root->rptr != NULL)
            root = root->rptr;

        return root->data;

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>