diff --git a/src/ch/zhaw/ads/AVLSearchTree.java b/src/ch/zhaw/ads/AVLSearchTree.java index ec63de5..6a6441f 100644 --- a/src/ch/zhaw/ads/AVLSearchTree.java +++ b/src/ch/zhaw/ads/AVLSearchTree.java @@ -18,7 +18,15 @@ public class AVLSearchTree> extends SortedBinaryTree @Override protected int calcSize(TreeNode p) { - // TODO Implement (6.2) + // Implement (6.2) + 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; } /** @@ -41,15 +49,18 @@ public class AVLSearchTree> extends SortedBinaryTree return null; } else if (height(p.left) - height(p.right) == 2) { if (height(p.left.left) >= height(p.left.right)) { - // TODO Implement (6.2) + // Implement (6.2) + p = rotateR(p); } else { - // TODO Implement (6.2) + p = rotateLR(p); } } else if (height(p.right) - height(p.left) == 2) { if (height(p.right.right) >= height(p.right.left)) { - // TODO Implement (6.2) + // Implement (6.2) + p = rotateL(p); } else { - // TODO Implement (6.2) + // Implement (6.2) + p = rotateRL(p); } } p.height = Math.max(height(p.left), height(p.right)) + 1;