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 ...
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}} else {node.Left = DeleteLeftMost(node.Left, node);return node;}private T LeftMost(Node node) {if (node.Left == null) {return node.Item;} else {return LeftMost(node.Left);}}private void Fix<strong>Tree</strong>AfterDeletion(Node curNode, Node parent,Node sibling, Node 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>);bool siblingRight<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>) {Case1(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>) {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 Case1(Node curNode, Node parent,Node sibling, Node gr<strong>and</strong>Parent) {if (siblingToRight) {parent.<strong>Red</strong> = !parent.<strong>Red</strong>;sibling.<strong>Red</strong> = !sibling.<strong>Red</strong>;if (gr<strong>and</strong>Parent != null) {if (parentToRight) {76 JOURNAL OF OBJECT TECHNOLOGY VOL. 4, NO. 2