Exp 5
Exp 5
AIM:
ALGORITHM:
2. If tree is Empty then insert the new Node as Root node with color Black and exit
4. If the parent of new Node is Black then exit from the operation.
5. If the parent of new Node is Red then check the color of parent node's sibling of
new Node.
6. If it is Black or NULL node then make a suitable Rotation and Recolour it.
7. If it is Red coloured node then perform Recolour and Recheck it. Repeat the same
if (!node)
return;
if (node->left)
DeleteNode(node->left);
if (node->right)
DeleteNode(node->right);
delete node;
}
};
int main()
{
RedBlack<int, int> tree;
for (int i = 1; i < 10; ++i)
tree.Insert(i, i);
tree.Delete(9);
tree.Delete(8);
tree.Dump();
return 0;
}
OUTPUT :
1B
2R
3B
4B
5B
6R
7R
RESULT:
Thus the C++ program to Red-Black tree was written, executed and verified
successfully.