0

rootNode (BSTN) で検索を使用して検索を再帰的に呼び出そうとしていますが、間違ったタイプを示すエラーが発生するか、rootNode のサブツリーで getNode (タイプ BST が未定義であるというエラー) を呼び出すとエラーが発生します。私が間違ったタイプを持っていること

package sizebst;



public class sizeBST {
sizeBSTN rootNode;

public SizeBST(BSTN root){
    rootNode =  root;
}



public boolean search(int target){
    //isn't complete but I want to recrusively search the tree calling methods from the other class
            getNode(rootNode.LSubtree, target);

}

これは、getNode を呼び出したいメソッドです。

package sizebst;


public class SizeBSTN {
SizeBSTN LSubtree;  
SizeBSTN RSubtree;  
int data; 
int size; 


public SizeBSTN(int data){
    LSubtree = null;
    RSubtree = null;
    this.data = data;
    size = 1;
}




public static SizeBSTN getNode(SizeBSTN node, int target){
// isn't working yet but it finds a node and returns it.




    }



}   
4

1 に答える 1

0

クラスtryのgetNodeメソッドstaticなのでSizeBSTN

SizeBSTN.getNode(rootNode.LSubtree, target);

代わりは

getNode(rootNode.LSubtree, target);

他の方法は、このメソッドを静的にインポートすることです

import static sizebst.SizeBSTN.getNode;

クラス参照なしで呼び出すことができるようになりました。

于 2013-07-06T21:52:26.033 に答える