public double FindMin()
{
Node current = root;
while (!(current.left == null))
current = current.left;
return current.Data;
}
public double FindMax()
{
Node current = root;
while (!(current.right == null))
current = current.right;
return current.Data;
}
This is an iterative solution of my Binary search tree’s functions to find out minimum and maximum value in a tree in C#. I want to change it to recursive but that code doesn’t seem right here
public double RecurfindMax(Node current)
{
//current = root;
if (current.left == null)
{
return -1;
}
else
//if (current.left != null)
{
return RecurfindMax(current = current.left);
//return current;
}
So can you tell me what’s wrong with this code?
You might want to check How to find height of BST iteratively? for a similar problem; the solutions there should be instructive.
Also, for your recursive solution, it should raise a red flag that it NEVER considers the right child.