Пример #1
0
 public void RightRotation()
 {
     //get the right Node of the current Left Node to prevent for loosing data
       BinaryNode rightOfLeft = leftNode.GetRightNode();
       //setup the leftNode to be the parent
       leftNode.setParent(parent);
       leftNode.SetRightNode(this);
       //setup the parent
       //check if I'm the left or the right node of the parent
       if(parent.getValue > value)
       {
     //I'm a left node
     parent.SetLeftNode(leftNode);
       }
       else
       {
     //I'm a right node
     parent.SetRightNode(leftNode);
       }
       //setup myself
       parent = leftNode;
       leftNode = null;
       //now look if the rightOfLeft has a value
       if(rightOfLeft != null)
       {
     parent.addValue(rightOfLeft.getValue());
       }
 }
Пример #2
0
 public void LeftRotation()
 {
     //get the left Node of the current Right node to prevent loosing data
       BinaryNode leftOfRight = rightNode.GetLeftNode();
       //setup the right node
       rightNode.setParent(parent);
       rightNode.SetLeftNode(this);
       //setup parent
       if(parent.getValue() > value)
       {
     //I'm a left node
     parent.SetLeftNode(rightNode);
       }
       else
       {
     //I'm a right Node
     parent.SetRightNode(rightNode);
       }
       //setup myself
       parent = leftNode;
       leftNode = null;
       //now look if the leftOfRight has a value
       if(leftOfRight != null)
       {
     parent.addValue(leftOfRight.getValue());
       }
 }