rendered paste bodypublic class Blatt3_4 {
public static void main(String[] args) {
Bintree bt1 = new Bintree(null, null);
Bintree bt2 = new Bintree(null, null);
Bintree bt3 = new Bintree(null, null);
Bintree bt4 = new Bintree(null, null);
Bintree bt5 = new Bintree(bt2, bt1);
Bintree bt6 = new Bintree(bt3, bt4);
Bintree bt7 = new Bintree(bt5, bt6);
Bintree gk1 = new Bintree(null,null);
Bintree gk2 = new Bintree(null,null);
Bintree gk3 = new Bintree(gk1,gk2);
Bintree gk4 = new Bintree(null,null);
Bintree gk5 = new Bintree(null,null);
Bintree gk6 = new Bintree(gk3,gk4);
Bintree gk7 = new Bintree(null,null);
Bintree gk8 = new Bintree(null,null);
Bintree gk9 = new Bintree(gk7,gk8);
Bintree gk10 = new Bintree(gk5,gk6);
Bintree gk11 = new Bintree(gk9,gk10);
System.out.println("Baum der Länge 3:");
btlength(bt7);
System.out.println("Baum der Länge 5:");
int i = btlength(gk11);
System.out.println(i);
}
public static boolean isNode(Bintree bt) {
if (bt.rightChild() != null) {
return true;
} else {
return false;
}
}
public static int btlength(Bintree bt) {
if (!isNode(bt)) {
return 1;
} else if (isNode(bt.leftChild()) && isNode(bt.rightChild())) {
return Math.max(btlength(bt.leftChild()) + 1,
btlength(bt.rightChild()) + 1);
} else if (isNode(bt.leftChild())) {
return Math.max(btlength(bt.leftChild()) + 1, 1);
} else {
return Math.max(1, btlength(bt.rightChild()) + 1);
}
}
}