Beispiel #1
0
 public static void rightRotate(Node x)
 {
     Node y = x.getLeft();
     x.setLeft (y.getRight ());
     if (!y.getRight ().Equals (nil)) {
         y.getRight ().setParent (x);
     }
     y.setParent (x.getParent ());
     if (x.getParent ().Equals (nil)) {
         root = y;
     } else if (x.Equals (x.getParent ().getRight ())) {
         x.getParent ().setRight (y);
     } else {
         x.getParent ().setLeft (y);
     }
     y.setRight (x);
     x.setParent (y);
     y.setSize (x.getSize ());
     x.setSize (x.getRight ().getSize () + x.getLeft ().getSize () + 1);
 }
Beispiel #2
0
 public static Node predecessor(Node x)
 {
     if (!x.getLeft().Equals(nil)) {
         return maximum (x.getLeft ());
     }
     Node y = x.getParent ();
     while (!y.Equals (nil) && x.Equals (y.getLeft ())) {
         x = y;
         y = y.getParent ();
     }
     return y;
 }
Beispiel #3
0
 public static void printTree(Node start, int level, string side)
 {
     if (!start.Equals(nil)) {
         Console.WriteLine ("(" + start.getKey() + " - " + start.getColor() + " - " + side + " - s: " + start.getSize() +  " - p: " + start.getPlayerNumber() + " [" + level + "])");
         printTree (start.getLeft (), level + 1, "left");
         printTree (start.getRight(), level + 1, "right");
     }
 }
Beispiel #4
0
 public static Node minimum(Node x)
 {
     while (!x.getLeft().Equals (nil)) {
         x = x.getLeft ();
     }
     return x;
 }