title: Level order traversal in a binary search tree in java
body: <p>I have made 4 different traversals for my binary search tree. I am stuck at the last one which is the level order traversal and I can't get seem to find out how to do it correctly.</p>
  
  <p>The main problem is that I don't know how to only search one level at a time, I only can figure out how to search either the whole left or whole right subtree.</p>
  
  <pre><code>private void preOrder(BinaryNode&lt;AnyType&gt; t )
      {
          if(isEmpty()){
              System.out.println("Empty");
          }
          if(t != null) {
              System.out.println(t.element);
              preOrder(t.left);
              preOrder(t.right);
          }
      }
  
      private void postOrder(BinaryNode&lt;AnyType&gt; t){
  
          if(isEmpty()){
              System.out.println("Empty");
          }
          if (t != null) {
              postOrder(t.left);
              postOrder(t.right);
              System.out.println(t.element);
          }
      }
  
      private void inOrder(BinaryNode&lt;AnyType&gt; t)
      {
          if(isEmpty()){
              System.out.println("Empty");
          }
  
          if (t != null) {
              inOrder(t.left);
              System.out.println(t.element);
              inOrder(t.right);
          }
      }
  
      private void levelOrder(BinaryNode&lt;AnyType&gt; t, int level)
      {
          if(isEmpty()){
              System.out.println("Empty");
          }
  
          if(height(t) == 2) {
              System.out.println(t.element);
  
          }else if(height(t) &gt; 1){
              levelOrder(t.left, level );
              levelOrder(t.right, level );
          }
  
      }
  </code></pre>