D&F学数据结构系列——红黑树

定义:一棵二叉查找树如果满足下面的红黑性质,则为一棵红黑树:

         1)每个结点不是红的就是黑的

         2)根结点是黑的

         3)每个叶结点是黑的

         4)如果一个结点是红的,它的两个儿子都是黑的(即不可能有两个连续的红色结点

         5)对于每个结点,从该结点到其子孙结点的所有路径上包含相同数目的黑结点

性质:

         这些约束确保了红黑树的关键特性: 从根到叶子的最长的可能路径不多于最短的可能路径的两倍长。结果是这个树大致上是平衡的。插入、删除和查找某个值的最坏情况下的时间复杂度与树的高度成比例。因为树的高度被控制,所以红黑树在最坏情况下都是高效的,而不同于普通的二叉查找树

         要知道为什么这些性质确保了这个结果,注意到性质4导致了路径不能有两个毗连的红色节点就足够了。最短的路径可能都是黑色节点,最长的可能路径有交替的红色和黑色节点。因为根据性质5所有最长的路径都有相同数目的黑色节点,这就表明了没有路径能多于任何其他路径的两倍长。

来源与应用:

*1972年 由Rudolf Bayer发明的,他称之为“对称二叉B树”,它现代的名字是Leo J. Guibas和 Robert Sedgewick 于1978年写的一篇论文中获得的。它是复杂的,但它的操作有着良好的最坏情况运行时间,并且在实践中是高效的: 它可以在O(log n)时间内做查找,插入和删除,这里的n 是树中元素的数目。

*红黑树多用在内部排序,即全放在内存中的,微软STL的map和set的内部实现就是红黑树。B树多用在内存里放不下,大部分数据存储在外存上时。因为B树层数少,因此可以确保每次操作,读取磁盘的次数尽可能的少。

*在Linux中有很多地方用到了RD树。Linux内核在管理vm_area_struct时就是采用了红黑树来维护内存块的。anticipatory, deadline, 和CFQ I/O调度都使用的是RB树进行请求跟踪,还有CD/DVD驱动的包管理也是如此。高精度计时器(high-resolutiontimer)使用RB树组织定时请求。

复杂度:

一棵有n个结点的红黑树的高度最多为2log(n+1)

操作:

因为每一个红黑树也是一个特化的二叉查找树,因此红黑树上的只读操作与普通二叉查找树上的只读操作相同。然而,在红黑树上进行插入操作和删除操作会导致不再符合红黑树的性质。恢复红黑树的性质需要少量(O(log n))的颜色变更(实际是非常快速的)和不超过三次树旋转(对于插入操作是两次)。虽然插入和删除很复杂,但操作时间仍可以保持为 O(log n) 次。

插入(5种情况):

通过下列函数,可以找到一个结点的叔父和祖父结点:

 

 1 node* grandparent(node *n){
 2    return n->parent->parent;
 3 }
 4 
 5 node* uncle(node *n){
 6    if(n->parent==grandparent(n)->left)
 7      return grandparent(n)->right;
 8    else
 9      return grandparent(n)->left;
10 }

 

情形1:新节点N为根节点,我们把它绘成黑色,满足性质2和5。

1 void insert_case1(node* n){
2    if(n->parent==NULL)
3      n->color=BLACK;
4    else
5      insert_case2(n);
6 }

情形2:新节点的父节点P是黑色的。所以性质4没有失效(新节点是红色的),性质5也未受到威胁,虽然新节点N有两个黑色的叶子子节点,但是新节点N是红色的并且它取代了原来的一个黑色的子节点,所以性质5仍然满足。

1 void insert_case2(node* n){
2    if(n->parent->color==BLACK)
3      return;         //插入此处后树仍是有效的
4    else
5      insert_case3(n);
6 }

注意:在下列情形下,我们假定新节点的父节点为红色,所以它有祖父结点;因为如果父节点是根节点,那么父节点应当是黑色。所以新节点总有一个叔父结点。

情形3:如果父节点P和叔父节点U二者都是红色,我们可以将它们两个重绘为黑色并重绘祖父节点为红色。因为通过父节点P或叔父节点U的任何路径都必定通过祖父节点G,在这些路径上的黑节点数目没有改变。但是,红色的祖父节点G的父节点也有可能是红色的,这就违反了性质4。为了解决这个问题,我们在祖父节点G上递归地进行情形1的整个过程。(把G当成是新加入的节点进行各种情形的检查)

 1 void insert_case3(node *n) {
 2      if (uncle(n) != NULL && uncle(n)->color == RED) {
 3          n->parent->color = BLACK;
 4          uncle(n)->color = BLACK;
 5          grandparent(n)->color = RED;
 6          insert_case1(grandparent(n));
 7      }
 8      else
 9          insert_case4(n);
10  }

注意:在余下的情况,我们假定父节点P是祖父节点G的左儿子。如果它是右儿子,情形4和情形5中所述的左和右对调。

情形4:父节点P是红色而叔父节点U是黑色或缺少,并且新节点N是父节点P的右儿子而父节点P是祖父节点G的左儿子。在这种情况下我们进行一次左旋,调换新节点N和父节点P的角色;接着,我们按情形5处理以前的父节点P以解决仍然失效的性质4。注意这个改变会导致某些路径通过它们以前不通过的新节点N(比如图中1号叶子节点)或不通过节点P(比如图中3号叶子节点),但由于这两个节点都是红色的,所以性质5仍有效。

 1 void insert_case4(node *n) {
 2      if (n == n->parent->right && n->parent == grandparent(n)->left) {
 3          rotate_left(n->parent);
 4          n = n->left;
 5      } else if (n == n->parent->left && n->parent == grandparent(n)->right) {
 6          rotate_right(n->parent);
 7          n = n->right;
 8      }
 9      insert_case5(n);
10  }

情形5: 父节点P是红色而叔父节点U是黑色或缺少,新节点N是其父节点的左子节点,而父节点P又是其父节点G的左子节点。在这种情形下,我们进行针对祖父节点G的一次右旋转; 在旋转产生的树中,以前的父节点P现在是新节点N和以前的祖父节点G的父节点。我们知道以前的祖父节点G是黑色,否则父节点P就不可能是红色(如果P和G都是红色就违反了性质4,所以G必须是黑色)。我们切换以前的父节点P和祖父节点G的颜色,结果的树满足性质4。性质5也仍然保持满足,因为通过这三个节点中任何一个的所有路径以前都通过祖父节点G,现在它们都通过以前的父节点P。在各自的情形下,这都是三个节点中唯一的黑色节点。

 1  void insert_case5(node *n) {
 2      n->parent->color = BLACK;
 3      grandparent(n)->color = RED;
 4      if (n == n->parent->left && n->parent == grandparent(n)->left) {
 5          rotate_right(grandparent(n));
 6      } else {
 7          /* Here, n == n->parent->right && n->parent == grandparent(n)->right */
 8          rotate_left(grandparent(n));
 9      }
10  }

注意插入实际上是原地算法,因为上述所有调用都使用了尾部递归

删除(6种情况)

如果需要删除的节点有两个儿子,那么问题可以被转化成删除另一个只有一个儿子的节点的问题(为了表述方便,这里所指的儿子,为非叶子节点的儿子)。对于二叉查找树,在删除带有两个非叶子儿子的节点的时候,我们找到要么在它的左子树中的最大元素、要么在它的右子树中的最小元素,并把它的值转移到要删除的节点中(如在这里所展示的那样)。我们接着删除我们从中复制出值的那个节点,它必定有少于两个非叶子的儿子。因为只是复制了一个值,不违反任何性质,这就把问题简化为如何删除最多有一个儿子的节点的问题。它不关心这个节点是最初要删除的节点还是我们从中复制出值的那个节点。

在本文余下的部分中,我们只需要讨论删除只有一个儿子的节点(如果它两个儿子都为空,即均为叶子,我们任意将其中一个看作它的儿子)。如果我们删除一个红色节点(此时该节点的儿子将都为叶子节点),它的父亲和儿子一定是黑色的。所以我们可以简单的用它的黑色儿子替换它,并不会破坏性质3和性质4。通过被删除节点的所有路径只是少了一个红色节点,这样可以继续保证性质5。另一种简单情况是在被删除节点是黑色而它的儿子是红色的时候。如果只是去除这个黑色节点,用它的红色儿子顶替上来的话,会破坏性质5,但是如果我们重绘它的儿子为黑色,则曾经通过它的所有路径将通过它的黑色儿子,这样可以继续保持性质5。

需要进一步讨论的是在要删除的节点和它的儿子二者都是黑色的时候,这是一种复杂的情况。我们首先把要删除的节点替换为它的儿子。出于方便,称呼这个儿子为N(在新的位置上),称呼它的兄弟(它父亲的另一个儿子)为S。在下面的示意图中,我们还是使用P称呼N的父亲,SL称呼S的左儿子,SR称呼S的右儿子。我们将使用下述函数找到兄弟节点:

1 node *sibling(node *n)
2 {
3         if (n == n->parent->left)
4                 return n->parent->right;
5         else
6                 return n->parent->left;
7 }

我们可以使用下列代码进行上述的概要步骤,这里的函数 replace_node 替换 child 到 n 在树中的位置。出于方便,在本章节中的代码将假定空叶子被用不是 NULL 的实际节点对象来表示(在插入章节中的代码可以同任何一种表示一起工作)。

 1 void delete_one_child(node *n)
 2 {
 3         /*
 4          * Precondition: n has at most one non-null child.
 5          */
 6         node *child = is_leaf(n->right) ? n->left : n->right;
 7  
 8         replace_node(n, child);
 9         if (n->color == BLACK) {
10                 if (child->color == RED)
11                         child->color = BLACK;
12                 else
13                         delete_case1(child);
14         }
15         free(n);
16 }

如果N和它初始的父亲是黑色,则删除它的父亲导致通过N的路径都比不通过它的路径少了一个黑色节点。因为这违反了性质5,树需要被重新平衡。有几种情形需要考虑:

情形1: N是新的根。在这种情形下,我们就做完了。我们从所有路径去除了一个黑色节点,而新根是黑色的,所以性质都保持着。

1 void delete_case1(node *n)
2 {
3         if (n->parent != NULL)
4                 delete_case2(n);
5 }

注意: 在情形2、5和6下,我们假定N是它父亲的左儿子。如果它是右儿子,则在这些情形下的应当对调。

情形2: S是红色。在这种情形下我们在N的父亲上做左旋转,把红色兄弟转换成N的祖父,我们接着对调N的父亲和祖父的颜色。完成这两个操作后,尽管所有路径上黑色节点的数目没有改变,但现在N有了一个黑色的兄弟和一个红色的父亲(它的新兄弟是黑色因为它是红色S的一个儿子),所以我们可以接下去按情形4情形5情形6来处理。

 1 void delete_case2(node *n)
 2 {
 3         struct node *s = sibling(n);
 4  
 5         if (s->color == RED) {
 6                 n->parent->color = RED;
 7                 s->color = BLACK;
 8                 if (n == n->parent->left)
 9                         rotate_left(n->parent);
10                 else
11                         rotate_right(n->parent);
12         } 
13         delete_case3(n);
14 }

情形3: N的父亲、S和S的儿子都是黑色的。在这种情形下,我们简单的重绘S为红色。结果是通过S的所有路径,它们就是以前通过N的那些路径,都少了一个黑色节点。因为删除N的初始的父亲使通过N的所有路径少了一个黑色节点,这使事情都平衡了起来。但是,通过P的所有路径现在比不通过P的路径少了一个黑色节点,所以仍然违反性质4。要修正这个问题,我们要从情形1开始,在P上做重新平衡处理。

 1 void delete_case3(node *n)
 2 {
 3         node *s = sibling(n);
 4  
 5         if ((n->parent->color == BLACK) &&
 6             (s->color == BLACK) &&
 7             (s->left->color == BLACK) &&
 8             (s->right->color == BLACK)) {
 9                 s->color = RED;
10                 delete_case1(n->parent);
11         } else
12                 delete_case4(n);
13 }

情形4: S和S的儿子都是黑色,但是N的父亲是红色。在这种情形下,我们简单的交换N的兄弟和父亲的颜色。这不影响不通过N的路径的黑色节点的数目,但是它在通过N的路径上对黑色节点数目增加了一,添补了在这些路径上删除的黑色节点。

 1 void delete_case4(node *n)
 2 {
 3         node *s = sibling(n);
 4  
 5         if ((n->parent->color == RED) &&
 6             (s->color == BLACK) &&
 7             (s->left->color == BLACK) &&
 8             (s->right->color == BLACK)) {
 9                 s->color = RED;
10                 n->parent->color = BLACK;
11         } else
12                 delete_case5(n);
13 }

情形5: S是黑色,S的左儿子是红色,S的右儿子是黑色,而N是它父亲的左儿子。在这种情形下我们在S上做右旋转,这样S的左儿子成为S的父亲和N的新兄弟。我们接着交换S和它的新父亲的颜色。所有路径仍有同样数目的黑色节点,但是现在N有了一个右儿子是红色的黑色兄弟,所以我们进入了情形6。N和它的父亲都不受这个变换的影响。

 1 void
 2 delete_case5(node *n)
 3 {
 4         node *s = sibling(n);
 5  
 6         if  (s->color == BLACK) { /* this if statement is trivial, 
 7 due to Case 2 (even though Case two changed the sibling to a sibling's child, 
 8 the sibling's child can't be red, since no red parent can have a red child). */
 9 // the following statements just force the red to be on the left of the left of the parent, 
10 // or right of the right, so case six will rotate correctly.
11                 if ((n == n->parent->left) &&
12                     (s->right->color == BLACK) &&
13                     (s->left->color == RED)) { // this last test is trivial too due to cases 2-4.
14                         s->color = RED;
15                         s->left->color = BLACK;
16                         rotate_right(s);
17                 } else if ((n == n->parent->right) &&
18                            (s->left->color == BLACK) &&
19                            (s->right->color == RED)) {// this last test is trivial too due to cases 2-4.
20                         s->color = RED;
21                         s->right->color = BLACK;
22                         rotate_left(s);
23                 }
24         }
25         delete_case6(n);
26 }

情形6: S是黑色,S的右儿子是红色,而N是它父亲的左儿子。在这种情形下我们在N的父亲上做左旋转,这样S成为N的父亲和S的右儿子的父亲。我们接着交换N的父亲和S的颜色,并使S的右儿子为黑色。子树在它的根上的仍是同样的颜色,所以性质3没有被违反。但是,N现在增加了一个黑色祖先: 要么N的父亲变成黑色,要么它是黑色而S被增加为一个黑色祖父。所以,通过N的路径都增加了一个黑色节点。

此时,如果一个路径不通过N,则有两种可能性:

  • 它通过N的新兄弟。那么它以前和现在都必定通过S和N的父亲,而它们只是交换了颜色。所以路径保持了同样数目的黑色节点。
  • 它通过N的新叔父,S的右儿子。那么它以前通过S、S的父亲和S的右儿子,但是现在只通过S,它被假定为它以前的父亲的颜色,和S的右儿子,它被从红色改变为黑色。合成效果是这个路径通过了同样数目的黑色节点。

在任何情况下,在这些路径上的黑色节点数目都没有改变。所以我们恢复了性质4。在示意图中的白色节点可以是红色或黑色,但是在变换前后都必须指定相同的颜色。

 1 void delete_case6(node *n)
 2 {
 3         node *s = sibling(n);
 4  
 5         s->color = n->parent->color;
 6         n->parent->color = BLACK;
 7  
 8         if (n == n->parent->left) {
 9                 s->right->color = BLACK;
10                 rotate_left(n->parent);
11         } else {
12                 s->left->color = BLACK;
13                 rotate_right(n->parent);
14         }
15 }

C++ 示例代码

  1 #define BLACK 1
  2 #define RED 0
  3  
  4 using namespace std;
  5  
  6 class bst {
  7 private:
  8  
  9     struct Node {
 10         int value;
 11         bool color;
 12         Node *leftTree, *rightTree, *parent;
 13  
 14         Node() {
 15             color = RED;
 16             leftTree = NULL;
 17             rightTree = NULL;
 18             parent = NULL;
 19             value = 0;
 20         }
 21  
 22         Node* grandparent() {
 23             if (parent == NULL) {
 24                 return NULL;
 25             }
 26             return parent->parent;
 27         }
 28  
 29         Node* uncle() {
 30             if (grandparent() == NULL) {
 31                 return NULL;
 32             }
 33             if (parent == grandparent()->rightTree)
 34                 return grandparent()->leftTree;
 35             else
 36                 return grandparent()->rightTree;
 37         }
 38  
 39         Node* sibling() {
 40             if (parent->leftTree == this)
 41                 return parent->rightTree;
 42             else
 43                 return parent->leftTree;
 44         }
 45     };
 46  
 47     void rotate_right(Node *p) {
 48         Node *gp = p->grandparent();
 49         Node *fa = p->parent;
 50         Node *y = p->rightTree;
 51  
 52         fa->leftTree = y;
 53  
 54         if (y != NIL)
 55             y->parent = fa;
 56         p->rightTree = fa;
 57         fa->parent = p;
 58  
 59         if (root == fa)
 60             root = p;
 61         p->parent = gp;
 62  
 63         if (gp != NULL) {
 64             if (gp->leftTree == fa)
 65                 gp->leftTree = p;
 66             else
 67                 gp->rightTree = p;
 68         }
 69  
 70     }
 71  
 72     void rotate_left(Node *p) {
 73         if (p->parent == NULL) {
 74             root = p;
 75             return;
 76         }
 77         Node *gp = p->grandparent();
 78         Node *fa = p->parent;
 79         Node *y = p->leftTree;
 80  
 81         fa->rightTree = y;
 82  
 83         if (y != NIL)
 84             y->parent = fa;
 85         p->leftTree = fa;
 86         fa->parent = p;
 87  
 88         if (root == fa)
 89             root = p;
 90         p->parent = gp;
 91  
 92         if (gp != NULL) {
 93             if (gp->leftTree == fa)
 94                 gp->leftTree = p;
 95             else
 96                 gp->rightTree = p;
 97         }
 98     }
 99  
100     void inorder(Node *p) {
101         if (p == NIL)
102             return;
103  
104         if (p->leftTree)
105             inorder(p->leftTree);
106  
107         cout << p->value << " ";
108  
109         if (p->rightTree)
110             inorder(p->rightTree);
111     }
112  
113     string outputColor(bool color) {
114         return color ? "BLACK" : "RED";
115     }
116  
117     Node* getSmallestChild(Node *p) {
118         if (p->leftTree == NIL)
119             return p;
120         return getSmallestChild(p->leftTree);
121     }
122  
123     bool delete_child(Node *p, int data) {
124         if (p->value > data) {
125             if (p->leftTree == NIL) {
126                 return false;
127             }
128             return delete_child(p->leftTree, data);
129         } else if (p->value < data) {
130             if (p->rightTree == NIL) {
131                 return false;
132             }
133             return delete_child(p->rightTree, data);
134         } else if (p->value == data) {
135             if (p->rightTree == NIL) {
136                 delete_one_child(p);
137                 return true;
138             }
139             Node *smallest = getSmallestChild(p->rightTree);
140             swap(p->value, smallest->value);
141             delete_one_child(smallest);
142  
143             return true;
144         }
145     }
146  
147     void delete_one_child(Node *p) {
148         Node *child = p->leftTree == NIL ? p->rightTree : p->leftTree;
149         if (p->parent == NULL && p->leftTree == NIL && p->rightTree == NIL) {
150             p = NULL;
151             return;
152         }
153  
154         if (p->parent == NULL) {
155             delete  p;
156             child->parent = NULL;
157             root = child;
158             return;
159         }
160  
161         if (p->parent->leftTree == p) {
162             p->parent->leftTree = child;
163         } else {
164             p->parent->rightTree = child;
165         }
166         child->parent = p->parent;
167  
168         if (p->color == BLACK) {
169             if (child->color == RED) {
170                 child->color = BLACK;
171             } else
172                 delete_case(child);
173         }
174  
175         delete p;
176     }
177  
178     void delete_case(Node *p) {
179         if (p->parent == NULL) {
180             p->color = BLACK;
181             return;
182         }
183         if (p->sibling()->color == RED) {
184             p->parent->color = RED;
185             p->sibling()->color = BLACK;
186             if (p == p->parent->leftTree)
187                 rotate_left(p->sibling());
188             else
189                 rotate_right(p->sibling());
190         }
191         if (p->parent->color == BLACK && p->sibling()->color == BLACK
192                 && p->sibling()->leftTree->color == BLACK && p->sibling()->rightTree->color == BLACK) {
193             p->sibling()->color = RED;
194             delete_case(p->parent);
195         } else if (p->parent->color == RED && p->sibling()->color == BLACK
196                 && p->sibling()->leftTree->color == BLACK && p->sibling()->rightTree->color == BLACK) {
197             p->sibling()->color = RED;
198             p->parent->color = BLACK;
199         } else {
200             if (p->sibling()->color == BLACK) {
201                 if (p == p->parent->leftTree && p->sibling()->leftTree->color == RED
202                         && p->sibling()->rightTree->color == BLACK) {
203                     p->sibling()->color = RED;
204                     p->sibling()->leftTree->color = BLACK;
205                     rotate_right(p->sibling()->leftTree);
206                 } else if (p == p->parent->rightTree && p->sibling()->leftTree->color == BLACK
207                         && p->sibling()->rightTree->color == RED) {
208                     p->sibling()->color = RED;
209                     p->sibling()->rightTree->color = BLACK;
210                     rotate_left(p->sibling()->rightTree);
211                 }
212             }
213             p->sibling()->color = p->parent->color;
214             p->parent->color = BLACK;
215             if (p == p->parent->leftTree) {
216                 p->sibling()->rightTree->color = BLACK;
217                 rotate_left(p->sibling());
218             } else {
219                 p->sibling()->leftTree->color = BLACK;
220                 rotate_right(p->sibling());
221             }
222         }
223     }
224  
225     void insert(Node *p, int data) {
226         if (p->value >= data) {
227             if (p->leftTree != NIL)
228                 insert(p->leftTree, data);
229             else {
230                 Node *tmp = new Node();
231                 tmp->value = data;
232                 tmp->leftTree = tmp->rightTree = NIL;
233                 tmp->parent = p;
234                 p->leftTree = tmp;
235                 insert_case(tmp);
236             }
237         } else {
238             if (p->rightTree != NIL)
239                 insert(p->rightTree, data);
240             else {
241                 Node *tmp = new Node();
242                 tmp->value = data;
243                 tmp->leftTree = tmp->rightTree = NIL;
244                 tmp->parent = p;
245                 p->rightTree = tmp;
246                 insert_case(tmp);
247             }
248         }
249     }
250  
251     void insert_case(Node *p) {
252         if (p->parent == NULL) {
253             root = p;
254             p->color = BLACK;
255             return;
256         }
257         if (p->parent->color == RED) {
258             if (p->uncle()->color == RED) {
259                 p->parent->color = p->uncle()->color = BLACK;
260                 p->grandparent()->color = RED;
261                 insert_case(p->grandparent());
262             } else {
263                 if (p->parent->rightTree == p && p->grandparent()->leftTree == p->parent) {
264                     rotate_left(p);
265                     rotate_right(p);
266                     p->color = BLACK;
267                     p->leftTree->color = p->rightTree->color = RED;
268                 } else if (p->parent->leftTree == p && p->grandparent()->rightTree == p->parent) {
269                     rotate_right(p);
270                     rotate_left(p);
271                     p->color = BLACK;
272                     p->leftTree->color = p->rightTree->color = RED;
273                 } else if (p->parent->leftTree == p && p->grandparent()->leftTree == p->parent) {
274                     p->parent->color = BLACK;
275                     p->grandparent()->color = RED;
276                     rotate_right(p->parent);
277                 } else if (p->parent->rightTree == p && p->grandparent()->rightTree == p->parent) {
278                     p->parent->color = BLACK;
279                     p->grandparent()->color = RED;
280                     rotate_left(p->parent);
281                 }
282             }
283         }
284     }
285  
286     void DeleteTree(Node *p) {
287         if (!p || p == NIL) {
288             return;
289         }
290         DeleteTree(p->leftTree);
291         DeleteTree(p->rightTree);
292         delete p;
293     }
294 public:
295  
296     bst() {
297         NIL = new Node();
298         NIL->color = BLACK;
299         root = NULL;
300     }
301  
302     ~bst() {
303         if (root)
304             DeleteTree(root);
305         delete NIL;
306     }
307  
308     void inorder() {
309         if (root == NULL)
310             return;
311         inorder(root);
312         cout << endl;
313     }
314  
315     void insert(int x) {
316         if (root == NULL) {
317             root = new Node();
318             root->color = BLACK;
319             root->leftTree = root->rightTree = NIL;
320             root->value = x;
321         } else {
322             insert(root, x);
323         }
324     }
325  
326     bool delete_value(int data) {
327         return delete_child(root, data);
328     }
329 private:
330     Node *root, *NIL;
331 };

维基百科:红黑树

原文地址:https://www.cnblogs.com/sage-blog/p/3868213.html