そこで、教授のバイナリ ツリー クラスに findHeight メソッドを追加しようとしていますが、少し問題があります。
BTNode<T> findParent(BTNode<T> Root, BTNode<T> child)
{
if(!root)
{
return Null;
}
if(Root.left* == child || Root.right* == child)
{
return Root;
}
else
{
//recursively checks left tree to see if child node is pointed to
findParent(Root.left, child);
//recursively checks right tree to see if child node is pointed to
findParent(Root.right, child);
}
int findHeight(BTNode<T> thisNode)
{
if (Count.findParent(.root, thisNode) == null)
{
return 0;
}
return findHeight(thisNode.findParent) + 1;
}
私の問題は、findHeight メソッドで findParent() メソッドが呼び出され、パラメータ thisNode が由来するバイナリ ツリーのルートを参照する必要があることです。これはクラスの一部にすぎないため、わかりませんルートを参照する方法。BT(バイナリツリー)クラスにはツリーのルートを返す関数がありますが、参照するバイナリツリーがないのでどうすればいいのかわかりません。助けてください!!!