Fixed AVLTrees pollFirst/pollLast

This commit is contained in:
2021-07-23 22:04:59 +02:00
parent 4a3cc66401
commit 73916f4fd9
4 changed files with 14 additions and 16 deletions
@@ -767,11 +767,11 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
entry.value = successor.value;
entry = successor;
}
if(entry.previous() == null) first = entry.next();
if(entry.next() == null) last = entry.previous();
Entry KEY_VALUE_GENERIC_TYPE replacement = entry.left != null ? entry.left : entry.right;
if(replacement != null) {
if(entry.replace(replacement)) tree = replacement;
if(entry == first) first = replacement;
if(entry == last) last = entry.right != null ? entry.right : replacement;
entry.left = entry.right = entry.parent = null;
fixAfterDeletion(replacement);
}
@@ -779,11 +779,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
else {
fixAfterDeletion(entry);
entry.replace(null);
if(entry.parent != null) {
Entry KEY_VALUE_GENERIC_TYPE parent = entry.parent;
if(entry == first) first = parent.left != null ? parent.left : parent;
if(entry == last) last = entry.right != null ? parent.right : parent;
}
entry.parent = null;
}
}