title: AVL Tree for Java
body: <p>I'm not sure if I'm doing this correctly as this is my very first time coding with nodes. But here's my code so far, if someone can look over it and help me out with understanding if I'm doing anything wrong. Also my insert/remove methods are giving me a hard time. The professor gave us the pseudocode for that but I can't seem to grasp how to interpret it into Java code as I've never done this type of code before. Mostly because there's a if statement that checks the heights to see if the tree is balanced, how would i implement height in this? Hints or any help is greatly appreciated, I've been stuck on this for a while. Thanks!</p>
  
  <p>I also don't think I did my constructor correctly and I'm unsure about it. The return in insert/remove can be ignored, it was just put in there to make sure the rest of the code will compile.</p>
  
  <pre><code>public class AvlNode{
  
      public static void main(String[]args){
  
      }
      //constructor
      public class AvlTreeNode{
          private int num;
          private AvlTreeNode left;
          private AvlTreeNode right;
  
          public AvlTreeNode left(){
              return this.left;
          }
  
          public AvlTreeNode right(){
              return this.right;
          }
  
          public int value(){
              return this.num;
          }
      }
      //method to find the number specified on the node
      public AvlTreeNode find(AvlTreeNode t, int x){
          if(t == null){
              return null;
          }
          if( t.value() == x){
              return t;
          }
          else if(x &lt; t.value()){
              return find(t.left(), x);
          }
          else{
              return find(t.right(), x);
          }
      }
      //method to insert a new node and number to a tree
      public AvlTreeNode insert(AvlTreeNode t, int x){
          if(t == null){
              t = new AvlTreeNode(x, null, null);
              return t;
          }
          if(x &lt; t.value()){
              t.left = insert(t.left(), x);
          }
          return t;
      }
      //method to remove a node and number from the tree
      public AvlTreeNode remove(AvlTreeNode t, int x){
          return t;
      }
      //Inorder traversal method, should print out numbers in ascending order if correct
      public void inOrder(AvlTreeNode t){
          if(t != null){
              inOrder(t.left());
              System.out.print(t.value() + " ");
              inOrder(t.right());
          }
      }
      //single rotation of nodes to balance tree, rotating leftwards
      public static AvlTreeNode singleRotateWithLeft( AvlTreeNode k1){
          AvlTreeNode k2 = k1.left;
          k1.left = k2.right;
          k2.right = k1;
          return k2;
      }
      //single rotation of nodes to balance tree, rotating rightwards
      public static AvlTreeNode singleRotateWithRight( AvlTreeNode k2){
          AvlTreeNode k1 = k2.right;
          k2.right = k1.left;
          k1.left = k2;
          return k1;
      }
      //double rotation of nodes towards the left
      public static AvlTreeNode doubleRotateWithLeft( AvlTreeNode k3){
          k3.left = doubleRotateWithRight(k3.left);
          return doubleRotateWithLeft(k3);
      }
      //double rotation of nodes towards the right
      public static AvlTreeNode doubleRotateWithRight( AvlTreeNode k2){
          k2.right = doubleRotateWithLeft(k2.right);
          return doubleRotateWithRight(k2);
      }
  }
  </code></pre>