Solved Task 4

This commit is contained in:
schrom01 2022-10-19 07:55:29 +02:00
parent 547f7ae499
commit 1462cdcaba
2 changed files with 17 additions and 5 deletions

View File

@ -22,7 +22,7 @@ public class RankingTreeServer implements CommandExecutor {
competitorTree.traversal().inorder(new Visitor<Competitor>() {
@Override
public void visit(Competitor obj) {
sb.append(rank.getAndAdd(1) + ". " + obj.getName() + ": " + obj.getTime() + "\n");
sb.append(rank.getAndAdd(1) + " " + obj.getName() + " " + obj.getTime() + "\n");
}
});
return sb.toString();

View File

@ -72,8 +72,14 @@ public class SortedBinaryTree<T extends Comparable<T>> implements Tree<T> {
}
protected int calcHeight(TreeNode<T> node) {
// TODO Implement
return 0;
int heigthLeft = 0, heigthRight = 0;
if(node.left != null){
heigthLeft = calcHeight(node.left);
}
if(node.right != null){
heigthRight = calcSize(node.right);
}
return Math.max(heigthLeft, heigthRight) + 1;
}
public int height() {
@ -81,8 +87,14 @@ public class SortedBinaryTree<T extends Comparable<T>> implements Tree<T> {
}
protected int calcSize(TreeNode<T> p) {
// TODO Implement
return 0;
int sizeLeft = 0, sizeRight = 0;
if(p.left != null){
sizeLeft = calcSize(p.left);
}
if(p.right != null){
sizeRight = calcSize(p.right);
}
return sizeLeft + sizeRight + 1;
}
public int size() {