diff --git a/src/main/java/net/abhinavsarkar/algorist/AVLTree.java b/src/main/java/net/abhinavsarkar/algorist/AVLTree.java index 91e2077..2d44854 100644 --- a/src/main/java/net/abhinavsarkar/algorist/AVLTree.java +++ b/src/main/java/net/abhinavsarkar/algorist/AVLTree.java @@ -220,20 +220,16 @@ public class AVLTree,V> implements Iterable 1) { ValueNode l = this.left.toValueNode(); - if (l.balance() > 0) { // left-left case - return this.rotateRight(); - } else { // left-right case + if (l.balance() <= 0) { // left-right case this.left = l.rotateLeft(); - return this.rotateRight(); } + return this.rotateRight(); } else if (balance < -1) { ValueNode r = this.right.toValueNode(); if (r.balance() > 0) { // right-left case this.right = r.rotateRight(); - return this.rotateLeft(); - } else { // right-right case - return this.rotateLeft(); } + return this.rotateLeft(); } return this; } @@ -467,8 +463,8 @@ public class AVLTree,V> implements Iterable { - private K key; - private V val; + private final K key; + private final V val; public Entry(K key, V val) { this.key = key;