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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

GENERIC RED-BLACK TREE AND ITS <strong>C#</strong> IMPLEMENTATION}} else if (!siblingToRight && !sibling<strong>Red</strong> &&!siblingLeft<strong>Red</strong> && siblingRight<strong>Red</strong>) {Case3P(curNode, parent, sibling, gr<strong>and</strong>Parent);} else if (siblingToRight && !sibling<strong>Red</strong> &&siblingRight<strong>Red</strong>) {Case4(curNode, parent, sibling, gr<strong>and</strong>Parent);} else if (!siblingToRight && !sibling<strong>Red</strong> &&siblingLeft<strong>Red</strong>) {Case4P(curNode, parent, sibling, gr<strong>and</strong>Parent);}private void Case2A(Node curNode, Node parent,Node sibling, Node gr<strong>and</strong>Parent) {if (sibling != null) {sibling.<strong>Red</strong> = !sibling.<strong>Red</strong>;}curNode = parent;if (curNode != root) {parent = curNode.Parent;GetParentGr<strong>and</strong>ParentSibling(curNode, parent,out sibling, out gr<strong>and</strong>Parent);Node siblingLeftChild = null;Node siblingRightChild = null;if (sibling != null && sibling.Left != null) {siblingLeftChild = sibling.Left;}if (sibling != null && sibling.Right != null) {siblingRightChild = sibling.Right;}bool sibling<strong>Red</strong> = (sibling != null && sibling.<strong>Red</strong>);bool siblingLeft<strong>Red</strong> = (siblingLeftChild != null &&siblingLeftChild.<strong>Red</strong>);}}boolsiblingRight<strong>Red</strong> = (siblingRightChild != null &&siblingRightChild.<strong>Red</strong>);if (parent != null && !parent.<strong>Red</strong> && !sibling<strong>Red</strong> &&!siblingLeft<strong>Red</strong> && !siblingRight<strong>Red</strong>) {Case2A(curNode, parent, sibling, gr<strong>and</strong>Parent);} else if (parent != null && parent.<strong>Red</strong> && !sibling<strong>Red</strong>&& !siblingLeft<strong>Red</strong> && !siblingRight<strong>Red</strong>) {Case2B(curNode, parent, sibling, gr<strong>and</strong>Parent);} else if (siblingToRight && !sibling<strong>Red</strong> &&siblingLeft<strong>Red</strong> && !siblingRight<strong>Red</strong>) {Case3(curNode, parent, sibling, gr<strong>and</strong>Parent);} else if (!siblingToRight && !sibling<strong>Red</strong> &&!siblingLeft<strong>Red</strong> && siblingRight<strong>Red</strong>) {Case3P(curNode, parent, sibling, gr<strong>and</strong>Parent);} else if (siblingToRight && !sibling<strong>Red</strong> &&siblingRight<strong>Red</strong>) {Case4(curNode, parent, sibling, gr<strong>and</strong>Parent);} else if (!siblingToRight && !sibling<strong>Red</strong> &&siblingLeft<strong>Red</strong>) {Case4P(curNode, parent, sibling, gr<strong>and</strong>Parent);}private void Case2B(Node curNode, Node parent,Node sibling, Node gr<strong>and</strong>Parent) {if (sibling != null) {sibling.<strong>Red</strong> = !sibling.<strong>Red</strong>;78 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!