11.4.树的旋转
树的旋转
The formal definition of rotation is:
rotateLeft(G): Let x be the right child of G. Make G the new left child of x.
rotateRight(G): Let x be the left child of G. Make G the new right child of x.
As in the picture, it means:
: G moves left, promote its right child in the only natural way.(Promoting P means P is the new parent of G.) : P moves right, promote its left child in the only natural way.
We can implement these operations by following codes:
1 | private Node rotateLeft(Node h) { |
Gitalking ...