How will you find the maximum element in a binary search tree?

How will you find the maximum element in a binary search tree?
A.
Code:
public void max(Tree root)
{
	while(root.left() != null)
	{
		root = root.left();
	}
	System.out.println(root.data());
}
B.
Code:
public void max(Tree root)
{
	while(root != null)
	{
		root = root.left();
	}
	System.out.println(root.data());
}
C.
Code:
public void max(Tree root)
{
	while(root.right() != null)
	{
		root = root.right();
	}
	System.out.println(root.data());
}
D.
Code:
public void max(Tree root)
{
	while(root != null)
	{
		root = root.right();
	}
	System.out.println(root.data());
}
 

Tìm kiếm

Back
Top