@@ -222,7 +222,7 @@ case Left-Left:// Left-Left insertion, unbalanced \\B perform right rotation to
222
222
for diagrams etc explaining rotations.
223
223
\\Expl}
224
224
\\In{
225
- return rightRotate(t) \\B return rightRotate(t)
225
+ return rightRotate(t) // raise Left-Left subtree to balance \\B return rightRotate(t)
226
226
\\In}
227
227
case Right-Right:// Right-Right insertion, unbalanced \\B perform left rotation to re-balance t
228
228
\\Expl{
@@ -233,7 +233,7 @@ case Right-Right:// Right-Right insertion, unbalanced \\B perform left rotation
233
233
for diagrams etc explaining rotations.
234
234
\\Expl}
235
235
\\In{
236
- return leftRotate(t) \\B return leftRotate(t)
236
+ return leftRotate(t) // raise Right-Right subtree to balance \\B return leftRotate(t)
237
237
\\In}
238
238
case Left-Right:// Left-Right insertion, unbalanced \\B perform left rotation on the left subtree
239
239
\\Expl{
@@ -248,9 +248,10 @@ case Left-Right:// Left-Right insertion, unbalanced \\B perform left rotation on
248
248
\\In{
249
249
perform leftRotate(left(t)); // raise Left-Right subtree \\B left(t) <- leftRotate(left(t));
250
250
\\Expl{
251
- The result returned is the new left(t).
251
+ The result returned is the new left(t). This lowers the Left-Left
252
+ subtree.
252
253
\\Expl}
253
- return rightRotate(t) \\B return rightRotate(t) after leftRotate
254
+ return rightRotate(t) // raise Left-Left subtree to balance \\B return rightRotate(t) after leftRotate
254
255
\\In}
255
256
case Right-Left:// Right-Left insertion, unbalanced \\B perform right rotation on the right subtree
256
257
\\Expl{
@@ -265,12 +266,13 @@ case Right-Left:// Right-Left insertion, unbalanced \\B perform right rotation o
265
266
\\In{
266
267
perform rightRotate(right(t)); // raise Right-Left subtree \\B right(t) <- rightRotate(right(t));
267
268
\\Expl{
268
- The result returned is the new right(t).
269
+ The result returned is the new right(t). This lowers the Right-Right
270
+ subtree.
269
271
\\Expl}
270
- return leftRotate(t) \\B return leftRotate(t) after rightRotate
272
+ return leftRotate(t) // raise Right-Right subtree to balance \\B return leftRotate(t) after rightRotate
271
273
\\In}
272
274
// ==== rotation functions ====
273
- leftRotate(t2) \\B leftRotate(t2)
275
+ leftRotate(t2) // raises Right-Right + lowers Left-Left subtrees \\B leftRotate(t2)
274
276
\\Expl{
275
277
The edge between t2 and its right child is "rotated" to the left
276
278
(counter-clockwise), and the right child becomes the new root.
0 commit comments