@@ -81,18 +81,18 @@ protected Node<T> addValue(T id) {
81
81
private void balanceAfterInsert (AVLNode <T > node ) {
82
82
int balanceFactor = node .getBalanceFactor ();
83
83
if (balanceFactor > 1 || balanceFactor < -1 ) {
84
- AVLNode <T > parent = ( AVLNode < T >) node . parent ;
84
+ AVLNode <T > child = null ;
85
85
Balance balance = null ;
86
86
if (balanceFactor < 0 ) {
87
- parent = (AVLNode <T >) node .lesser ;
88
- balanceFactor = parent .getBalanceFactor ();
87
+ child = (AVLNode <T >) node .lesser ;
88
+ balanceFactor = child .getBalanceFactor ();
89
89
if (balanceFactor < 0 )
90
90
balance = Balance .LEFT_LEFT ;
91
91
else
92
92
balance = Balance .LEFT_RIGHT ;
93
93
} else {
94
- parent = (AVLNode <T >) node .greater ;
95
- balanceFactor = parent .getBalanceFactor ();
94
+ child = (AVLNode <T >) node .greater ;
95
+ balanceFactor = child .getBalanceFactor ();
96
96
if (balanceFactor < 0 )
97
97
balance = Balance .RIGHT_LEFT ;
98
98
else
@@ -101,11 +101,11 @@ private void balanceAfterInsert(AVLNode<T> node) {
101
101
102
102
if (balance == Balance .LEFT_RIGHT ) {
103
103
// Left-Right (Left rotation, right rotation)
104
- rotateLeft (parent );
104
+ rotateLeft (child );
105
105
rotateRight (node );
106
106
} else if (balance == Balance .RIGHT_LEFT ) {
107
107
// Right-Left (Right rotation, left rotation)
108
- rotateRight (parent );
108
+ rotateRight (child );
109
109
rotateLeft (node );
110
110
} else if (balance == Balance .LEFT_LEFT ) {
111
111
// Left-Left (Right rotation)
@@ -115,8 +115,8 @@ private void balanceAfterInsert(AVLNode<T> node) {
115
115
rotateLeft (node );
116
116
}
117
117
118
+ child .updateHeight ();
118
119
node .updateHeight ();
119
- parent .updateHeight ();
120
120
}
121
121
}
122
122
0 commit comments