given the following node class for a binary search tree writ

given the following node class for a binary search tree, write a java method that finds and returns the minimum element of the right subtree of a given node. If the right subtree of a node is empty, then the method returns -10,000.

class BSTNode {

int value;

BSTNode left;

BSTNode right;

public BSTNode (int val) {

value = val;

left = null;

right = null;

}

}

Solution

int findMinRightSubTree(struct node* root)

{

if(root == NULL)

return -10000;

struct node* temp = root;

while (temp->left != NULL)

temp = temp->left;

return temp->data;

}

int res = findMinRightSubTree(root->right);

if(res != -10000)

printf(\"\ Minimum Right Subtree value in BST is %d\ \", res);

else

printf(\"\ There is no Right Subtree \");

NOTE : I have provided the method which finds minimum element at right subtree along with few lines of how to call it and print the return value. If you want full code, the please let me know. Thanks.


Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site