title: how do i do binary search tree rotation in java?
body: <p>SO I am writing a code for a project where I am to rotate a node to the left and rotate it to the right, I have it written out but when I run it two things occur, my rotate left method is rotating to the right rather than left, I've tried changing things around it still rotates to the right, as for my rotate right i get the null pointer exception when i try to run it. I can only use one return statement per method and has to be done recursively here are the two methods, I am in desperate need of help!! </p>
  
  <pre><code>   public void rotateLeft(int num) {
        root=rotateLeft(root,num);
  
  
      }
      private static IntNode rotateLeft(IntNode T,int num){
  
        //easiest case
        if(T==null)
        {
        }
          //rotation part       
        else if(num==T.getNum())
        {
           IntNode oldRight=T.getRight();
           if(T.getRight()!=null){
            T.setRight(oldRight.getLeft());
           oldRight.setLeft(T);
           T=oldRight;
           }
           else {
           }
        }
         else if(num&gt;T.getNum())
        {
           T.setRight(rotateLeft(T.getRight(),num));
        }
        //recursion
        else
        {
           T.setLeft(rotateLeft(T.getLeft(),num));
  }
  
  
        return  T;
  
  
  
  
           }
    // Rotate the node containing num to the right -- do nothing if not possible
      public void rotateRight(int num) {
        root=rotateRight(root,num);
      }
      private static IntNode rotateRight(IntNode T,int num)
      {
        IntNode oldLeft=T.getLeft();
  
        //easiest case
        if(T==null)
        {
  
        }
        //rotation part
          else if(num==T.getNum())
        {
           if(T.getLeft()!=null){
            T.setLeft(oldLeft.getLeft());
           oldLeft.setRight(T);
           T=oldLeft;
           }
           else {
           }
        }
         else if(num&gt;T.getNum())
        {
           T.setLeft(rotateRight(T.getLeft(),num));
        }
        else
        {
           T.setRight(rotateRight(T.getRight(),num));
  }
  
  
  
  
  
  
       return T;
  
      }
  </code></pre>