10.07.2015 Views

Generic Red-Black Tree and its C# Implementation - The Journal of ...

Generic Red-Black Tree and its C# Implementation - The Journal of ...

Generic Red-Black Tree and its C# Implementation - The Journal of ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

GENERIC RED-BLACK TREE AND ITS <strong>C#</strong> IMPLEMENTATION}}}Node curNode = null; // Right node being deletedif (nodeBeingDeleted.Right != null) {curNode = nodeBeingDeleted.Right;}Node parent, sibling, gr<strong>and</strong>Parent;if (curNode == null) {parent = nodeBeingDeleted.Parent;} else {parent = curNode.Parent;}GetParentGr<strong>and</strong>ParentSibling(curNode, parent,out sibling, out gr<strong>and</strong>Parent);if (curNode != null && curNode.<strong>Red</strong>) {curNode.<strong>Red</strong> = false;} else if (!nodeToDelete<strong>Red</strong> && !nodeBeingDeleted.<strong>Red</strong>) {Fix<strong>Tree</strong>AfterDeletion(curNode, parent,sibling, gr<strong>and</strong>Parent);}root.<strong>Red</strong> = false;// Queriesprivate Node InsertNode(Node node, T item, Node parent) {// Presented in previous listing}private void RightRotate(ref Node node) {// Presented earlier}private void LeftRotate(ref Node node) {// Presented earlier}private void GetNodesAbove(Node curNode, out Node parent,out Node gr<strong>and</strong>Parent,out Node greatGr<strong>and</strong>Parent) {// Presented in previous listing}private void GetParentGr<strong>and</strong>ParentSibling(Node curNode,Node parent,out Node sibling, out Node gr<strong>and</strong>Parent) {sibling = null;gr<strong>and</strong>Parent = null;if (parent != null) {if (parent.Right == curNode) {siblingToRight = false;sibling = parent.Left;}if (parent.Left == curNode) {siblingToRight = true;sibling = parent.Right;}}if (parent != null) {gr<strong>and</strong>Parent = parent.Parent;74 JOURNAL OF OBJECT TECHNOLOGY VOL. 4, NO. 2

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!