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;
}
這是我的二叉搜索樹的函數的迭代解決方案,以找出C#中樹中的最小值和最大值。我想改變它遞歸,但代碼似乎並不在這裏BST中的迭代和遞歸解決方案
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;
}
所以你能告訴我這個代碼有什麼問題嗎?
謝謝我的想法,遞歸的問題是因爲國旗..謝謝 – Rdx