tree가 binaryTree의 인스턴스 인 경우 카운터 값을 업데이트해야하는 다음 의사 코드가 있습니다. 트리에 더 많은 자식이있는 경우이 메서드를 재귀 적으로 호출합니다. & 카운터를 증가시킵니다.재귀 중 변수 값 보존
문제 I (나는 싶지 않은) 대향 고정 할 경우, 카운터 값이 미세하지만 (아래에 언급 된 바와 같이) I이 방법에 대한 입력으로서 변수를 통과 할 때 I 단지 가치를 1 여기서 뭐가 잘못 됐니?
//Pseudo code
public static int test(tree) {
Integer count = 0;
return testTreeRecCounts(tree, count);
}
private static Integer testTreeRecursiveCounts(tree, Integer count) {
if (tree instanceof binaryTree) {
count++;
for (Node node :tree.getChild())) {
testTreeRecursiveCounts((tree)node, count);
}
}
return count;
}
당신은뿐만 아니라 for' 루프'에서'testTreeRecursiveCounts' 메소드 호출의 결과를 추가해야 적절한 결과를 얻을 수 있습니다. – Antoniossss