From a63689aeb0158e4d4a8e776ba3d883a47d56f9ce Mon Sep 17 00:00:00 2001 From: schrom01 Date: Tue, 25 Oct 2022 15:48:02 +0200 Subject: [PATCH] solved Task 3 --- src/ch/zhaw/ads/AVLSearchTree.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ch/zhaw/ads/AVLSearchTree.java b/src/ch/zhaw/ads/AVLSearchTree.java index 6a6441f..ad649f2 100644 --- a/src/ch/zhaw/ads/AVLSearchTree.java +++ b/src/ch/zhaw/ads/AVLSearchTree.java @@ -8,7 +8,11 @@ package ch.zhaw.ads; */ public class AVLSearchTree> extends SortedBinaryTree { private boolean balanced(TreeNode node) { - // TODO Implement (6.4) + if(Math.abs(calcHeight(node.right) - calcHeight(node.left)) > 1 + || (node.right != null && !balanced(node.right)) + || (node.left != null && !balanced(node.left))){ + return false; + } return true; }