Advertisement
Guest User

Untitled

a guest
Feb 11th, 2013
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.24 KB | None | 0 0
  1. internal virtual bool DoRemove(T item)
  2. {
  3.     if (this.root == null)
  4.         return false;
  5.  
  6.     this.version++;
  7.     SortedSet<T>.Node node = this.root;
  8.     SortedSet<T>.Node node2 = null;
  9.     SortedSet<T>.Node node3 = null;
  10.     SortedSet<T>.Node node4 = null;
  11.     SortedSet<T>.Node parentOfMatch = null;
  12.     bool flag = false;
  13.     while (node != null)
  14.     {
  15.         if (SortedSet<T>.Is2Node(node))
  16.         {
  17.             if (node2 == null)
  18.             {
  19.                 node.IsRed = true;
  20.             }
  21.             else
  22.             {
  23.                 SortedSet<T>.Node node5 = SortedSet<T>.GetSibling(node, node2);
  24.                 if (node5.IsRed)
  25.                 {
  26.                     if (node2.Right == node5)
  27.                         SortedSet<T>.RotateLeft(node2);
  28.                     else
  29.                         SortedSet<T>.RotateRight(node2);
  30.                     node2.IsRed = true;
  31.                     node5.IsRed = false;
  32.                     this.ReplaceChildOfNodeOrRoot(node3, node2, node5);
  33.                     node3 = node5;
  34.                     if (node2 == node4)
  35.                         parentOfMatch = node5;
  36.                     node5 = ((node2.Left == node) ? node2.Right : node2.Left);
  37.                 }
  38.                 if (SortedSet<T>.Is2Node(node5))
  39.                 {
  40.                     SortedSet<T>.Merge2Nodes(node2, node, node5);
  41.                 }
  42.                 else
  43.                 {
  44.                     TreeRotation treeRotation = SortedSet<T>.RotationNeeded(node2, node, node5);
  45.                     SortedSet<T>.Node node6 = null;
  46.                     switch (treeRotation)
  47.                     {
  48.                     case TreeRotation.LeftRotation:
  49.                         node5.Right.IsRed = false;
  50.                         node6 = SortedSet<T>.RotateLeft(node2);
  51.                         break;
  52.                     case TreeRotation.RightRotation:
  53.                         node5.Left.IsRed = false;
  54.                         node6 = SortedSet<T>.RotateRight(node2);
  55.                         break;
  56.                     case TreeRotation.RightLeftRotation:
  57.                         node6 = SortedSet<T>.RotateRightLeft(node2);
  58.                         break;
  59.                     case TreeRotation.LeftRightRotation:
  60.                         node6 = SortedSet<T>.RotateLeftRight(node2);
  61.                         break;
  62.                     }
  63.                     node6.IsRed = node2.IsRed;
  64.                     node2.IsRed = false;
  65.                     node.IsRed = true;
  66.                     this.ReplaceChildOfNodeOrRoot(node3, node2, node6);
  67.                     if (node2 == node4)
  68.                         parentOfMatch = node6;
  69.                 }
  70.             }
  71.         }
  72.         int num = flag ? -1 : this.comparer.Compare(item, node.Item);
  73.         if (num == 0)
  74.         {
  75.             flag = true;
  76.             node4 = node;
  77.             parentOfMatch = node2;
  78.         }
  79.         node3 = node2;
  80.         node2 = node;
  81.         if (num < 0)
  82.             node = node.Left;
  83.         else
  84.             node = node.Right;
  85.     }
  86.     if (node4 != null)
  87.     {
  88.         this.ReplaceNode(node4, parentOfMatch, node2, node3);
  89.         this.count--;
  90.     }
  91.     if (this.root != null)
  92.         this.root.IsRed = false;
  93.     return flag;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement