我的递归逻辑有什么问题?
我'm trying to find the size of an m-ary tree. An MTree Node'的子节点由我实现的ArrayList表示 . 我的逻辑是 for
循环和 m
一样大,所以我可以检查每个孩子 .
public AnyType element;
public int m; // MTreeNode will have m children at most
public static ArrayList<MTreeNode> children;
public MTreeNode(AnyType element, int m, ArrayList<MTreeNode> children){
this.element = element;
this.m = m;
this.children = children;
public static int size(MTreeNode<?> t){
int nodes = 0;
if(t == null)
return 0;
else{
for(int i = 0; i < t.m; i++){
size(t.children.get(i));
}
return 1 + nodes;
}
}
我收到了我的错误
size(t.children.get(i));