MCPcopy Create free account
hub / github.com/acm-clan/algorithm-stone / leftRotate

Method leftRotate

templates/red-black-tree.cpp:86–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84 }
85
86 void leftRotate(RBTreeNode* x)
87 {
88 // x左移,x的右孩子y成为根节点,y的左孩子成为x的右孩子,其他不动
89 // 看起来就像是x左移了
90 auto y = x->right;
91
92 // 1 x的右节点变化
93 x->right = y->left;
94
95 // 更新left的父节点
96 if (y->left != nil) {
97 y->left->p = x;
98 }
99
100 // 2 根节点变化,更换根节点
101 y->p = x->p;
102
103 // 如果x是根节点,将root设置为y
104 transplant(x, y);
105
106 // 3 y的左孩子
107 y->left = x;
108 x->p = y;
109 }
110
111 void rightRotate(RBTreeNode* x)
112 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected