我的递归逻辑出了什么问题?
我正试图找到m-ary树的大小。 MTree节点的子节点由我实现的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));