◆ RBtree()
◆ del()
139 cout <<
"\nEmpty Tree.";
143 cout <<
"\nEnter the key of the node to be deleted: ";
150 while (p != NULL && found == 0)
164 cout <<
"\nElement Not Found.";
169 cout <<
"\nDeleted Element: " << p->key;
170 cout <<
"\nColour: ";
176 if (p->parent != NULL)
177 cout <<
"\nParent: " << p->parent->key;
179 cout <<
"\nThere is no parent of the node. ";
180 if (p->right != NULL)
181 cout <<
"\nRight Child: " << p->right->key;
183 cout <<
"\nThere is no right child of the node. ";
185 cout <<
"\nLeft Child: " << p->left->key;
187 cout <<
"\nThere is no left child of the node. ";
188 cout <<
"\nNode Deleted.";
189 if (p->left == NULL || p->right == NULL)
197 if (y->right != NULL)
203 q->parent = y->parent;
204 if (y->parent == NULL)
208 if (y == y->parent->left)
211 y->parent->right = q;
Definition: avltree.cpp:13
◆ delfix()
| void RBtree::delfix |
( |
node * |
p | ) |
|
226 while (p != root && p->color ==
'b')
228 if (p->parent->left == p)
230 s = p->parent->right;
234 p->parent->color =
'r';
235 leftrotate(p->parent);
236 s = p->parent->right;
238 if (s->right->color ==
'b'&&s->left->color ==
'b')
245 if (s->right->color ==
'b')
247 s->left->color =
'b';
250 s = p->parent->right;
252 s->color = p->parent->color;
253 p->parent->color =
'b';
254 s->right->color =
'b';
255 leftrotate(p->parent);
265 p->parent->color =
'r';
266 rightrotate(p->parent);
269 if (s->left->color ==
'b'&&s->right->color ==
'b')
276 if (s->left->color ==
'b')
278 s->right->color =
'b';
283 s->color = p->parent->color;
284 p->parent->color =
'b';
285 s->left->color =
'b';
286 rightrotate(p->parent);
◆ disp()
◆ display()
| void RBtree::display |
( |
node * |
p | ) |
|
380 cout <<
"\nEmpty Tree.";
385 cout <<
"\n\t NODE: ";
386 cout <<
"\n Key: " << p->key;
387 cout <<
"\n Colour: ";
392 if (p->parent != NULL)
393 cout <<
"\n Parent: " << p->parent->key;
395 cout <<
"\n There is no parent of the node. ";
396 if (p->right != NULL)
397 cout <<
"\n Right Child: " << p->right->key;
399 cout <<
"\n There is no right child of the node. ";
401 cout <<
"\n Left Child: " << p->left->key;
403 cout <<
"\n There is no left child of the node. ";
407 cout <<
"\n\nLeft:\n";
414 cout <<
"\n\nRight:\n";
#define endl
Definition: matrix_exponentiation.cpp:36
◆ insert()
37 cout <<
"\nEnter key of the node to be inserted: ";
◆ insertfix()
| void RBtree::insertfix |
( |
node * |
t | ) |
|
78 while (t->parent != NULL && t->parent->color ==
'r')
80 node *g = t->parent->parent;
81 if (g->left == t->parent)
88 t->parent->color =
'b';
96 if (t->parent->right == t)
101 t->parent->color =
'b';
113 t->parent->color =
'b';
121 if (t->parent->left == t)
126 t->parent->color =
'b';
◆ leftrotate()
| void RBtree::leftrotate |
( |
node * |
p | ) |
|
297 if (p->right == NULL)
309 if (p->parent != NULL)
310 y->parent = p->parent;
311 if (p->parent == NULL)
315 if (p == p->parent->left)
318 p->parent->right = y;
◆ rightrotate()
| void RBtree::rightrotate |
( |
node * |
p | ) |
|
331 if (y->right != NULL)
334 y->right->parent = p;
338 if (p->parent != NULL)
339 y->parent = p->parent;
340 if (p->parent == NULL)
344 if (p == p->parent->left)
347 p->parent->right = y;
◆ search()
425 cout <<
"\nEmpty Tree\n";
429 cout <<
"\n Enter key of the node to be searched: ";
433 while (p != NULL && found == 0)
446 cout <<
"\nElement Not Found.";
449 cout <<
"\n\t FOUND NODE: ";
450 cout <<
"\n Key: " << p->key;
451 cout <<
"\n Colour: ";
456 if (p->parent != NULL)
457 cout <<
"\n Parent: " << p->parent->key;
459 cout <<
"\n There is no parent of the node. ";
460 if (p->right != NULL)
461 cout <<
"\n Right Child: " << p->right->key;
463 cout <<
"\n There is no right child of the node. ";
465 cout <<
"\n Left Child: " << p->left->key;
467 cout <<
"\n There is no left child of the node. ";
◆ successor()
360 while (y->right != NULL)
366 while (y->left != NULL)
The documentation for this class was generated from the following file:
- data_structures/rb_tree.cpp