이 방법에 어떤 문제가 있습니까? 그것은 보인다. 그러나 나는 나무에서 인접한 아이들의 비교가 일어나지 않는다고 확신하지 않는다.나무에있는 인접한 아이들의 비교가 일어나지 않습니까?
방법으로 문제가
것 같다 나는 대략 손으로이 알고리즘의 동작을 추적하고 나는 아이디어가 구현에 문제가 어쩌면 올바른 생각이나 내가 재귀 작품, 두 번째 도우미 (비교)하는 방법을 몰라public static int MAX(BST B) {
int m = ((Integer) B.root.data).intValue();
return call(B.root, m);
}
public static int call(node current, int max) {
//first helper method gets the max from two different levels in the tree
if(current == null)
return -1;
if(current.left == null && current.right == null)
return max;
else {
if(((Integer) current.data).intValue()>max)
max = ((Integer) current.data).intValue();
return compare(call(current.left,max),call(current.right,max));
}
}
//second helper method gets the max
static int compare(int m1, int m2) {
if(m1>m2)
return m1;
else
return m2;
}
언어 태그를 추가하십시오. – Jon