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}}greatGr<strong>and</strong>Parent.Left = gr<strong>and</strong>Parent;}} else {LeftRotate(ref root);}} else if (gr<strong>and</strong>Parent.Left == parent &&parent.Left == child) { // left-left caseparent.<strong>Red</strong> = false;gr<strong>and</strong>Parent.<strong>Red</strong> = true;if (greatGr<strong>and</strong>Parent != null) {if (greatGr<strong>and</strong>Parent.Right == gr<strong>and</strong>Parent) {RightRotate(ref gr<strong>and</strong>Parent);greatGr<strong>and</strong>Parent.Right = gr<strong>and</strong>Parent;} else {RightRotate(ref gr<strong>and</strong>Parent);greatGr<strong>and</strong>Parent.Left = gr<strong>and</strong>Parent;}} else {RightRotate(ref root);}} else if (gr<strong>and</strong>Parent.Right == parent &&parent.Left == child) {// right-left casechild.<strong>Red</strong> = false;gr<strong>and</strong>Parent.<strong>Red</strong> = true;RightRotate(ref parent);gr<strong>and</strong>Parent.Right = parent;if (greatGr<strong>and</strong>Parent != null) {if (greatGr<strong>and</strong>Parent.Right == gr<strong>and</strong>Parent) {LeftRotate(ref gr<strong>and</strong>Parent);greatGr<strong>and</strong>Parent.Right = gr<strong>and</strong>Parent;} else {LeftRotate(ref gr<strong>and</strong>Parent);greatGr<strong>and</strong>Parent.Left = gr<strong>and</strong>Parent;}} else {LeftRotate(ref root);}} else if (gr<strong>and</strong>Parent.Left == parent &&parent.Right == child) {// left-right casechild.<strong>Red</strong> = false;gr<strong>and</strong>Parent.<strong>Red</strong> = true;LeftRotate(ref parent);gr<strong>and</strong>Parent.Left = parent;if (greatGr<strong>and</strong>Parent != null) {if (greatGr<strong>and</strong>Parent.Right == gr<strong>and</strong>Parent) {RightRotate(ref gr<strong>and</strong>Parent);greatGr<strong>and</strong>Parent.Right = gr<strong>and</strong>Parent;} else {RightRotate(ref gr<strong>and</strong>Parent);greatGr<strong>and</strong>Parent.Left = gr<strong>and</strong>Parent;}} else {RightRotate(ref root);}}}if (root.<strong>Red</strong>) {root.<strong>Red</strong> = false;}72 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!