JAVA-25491 better variable naming AVL Tree insert method

This commit is contained in:
kasramp 2023-10-30 21:42:36 +01:00
parent e984098398
commit d5c1b161bb
1 changed files with 7 additions and 7 deletions

View File

@ -42,17 +42,17 @@ public class AVLTree {
return root == null ? -1 : root.height;
}
private Node insert(Node node, int key) {
if (node == null) {
private Node insert(Node root, int key) {
if (root == null) {
return new Node(key);
} else if (node.key > key) {
node.left = insert(node.left, key);
} else if (node.key < key) {
node.right = insert(node.right, key);
} else if (root.key > key) {
root.left = insert(root.left, key);
} else if (root.key < key) {
root.right = insert(root.right, key);
} else {
throw new RuntimeException("duplicate Key!");
}
return rebalance(node);
return rebalance(root);
}
private Node delete(Node node, int key) {