Solved Task 4
This commit is contained in:
parent
547f7ae499
commit
1462cdcaba
|
@ -22,7 +22,7 @@ public class RankingTreeServer implements CommandExecutor {
|
||||||
competitorTree.traversal().inorder(new Visitor<Competitor>() {
|
competitorTree.traversal().inorder(new Visitor<Competitor>() {
|
||||||
@Override
|
@Override
|
||||||
public void visit(Competitor obj) {
|
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();
|
return sb.toString();
|
||||||
|
|
|
@ -72,8 +72,14 @@ public class SortedBinaryTree<T extends Comparable<T>> implements Tree<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int calcHeight(TreeNode<T> node) {
|
protected int calcHeight(TreeNode<T> node) {
|
||||||
// TODO Implement
|
int heigthLeft = 0, heigthRight = 0;
|
||||||
return 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() {
|
public int height() {
|
||||||
|
@ -81,8 +87,14 @@ public class SortedBinaryTree<T extends Comparable<T>> implements Tree<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int calcSize(TreeNode<T> p) {
|
protected int calcSize(TreeNode<T> p) {
|
||||||
// TODO Implement
|
int sizeLeft = 0, sizeRight = 0;
|
||||||
return 0;
|
if(p.left != null){
|
||||||
|
sizeLeft = calcSize(p.left);
|
||||||
|
}
|
||||||
|
if(p.right != null){
|
||||||
|
sizeRight = calcSize(p.right);
|
||||||
|
}
|
||||||
|
return sizeLeft + sizeRight + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int size() {
|
public int size() {
|
||||||
|
|
Loading…
Reference in New Issue