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.

LeftRotate(ref parent);gr<strong>and</strong>Parent.Right = parent;} else if (!parentToRight) {LeftRotate(ref parent);gr<strong>and</strong>Parent.Left = parent;}} else {LeftRotate(ref parent);root = parent;}gr<strong>and</strong>Parent = sibling;parent = parent.Left;parentToRight = false;} else 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) {RightRotate(ref parent);gr<strong>and</strong>Parent.Right = parent;} else if (!parentToRight) {RightRotate(ref parent);gr<strong>and</strong>Parent.Left = parent;}} else {RightRotate(ref parent);root = parent;}gr<strong>and</strong>Parent = sibling;parent = parent.Right;parentToRight = true;}if (parent.Right == curNode) {sibling = parent.Left;siblingToRight = false;} else if (parent.Left == curNode) {sibling = parent.Right;siblingToRight = true;}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.<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);VOL. 4, NO. 2 JOURNAL OF OBJECT TECHNOLOGY 77

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

Saved successfully!

Ooh no, something went wrong!