Trying to implement level order traversal on a binary search tree in Java
<p>Okay, so I'm trying to make a method that will return the level order of a basic binary search tree that carries int values in its nodes. I've figured out most of the other methods, such as insertion, post order and pre order, but I keep running into the same problem with the level order method</p>

<p>Here's the code:</p>

<pre><code>private DoubleStackQueue&lt;Node&gt; queue = new DoubleStackQueue&lt;Node&gt;();
//this is a queue that uses two stacks, one for the front and one for the back.
//it works just like a queue.
public String levelOrder(){  
    s = "";  //The s is a private String that is implemented earlier
    queue.add(this);  
    while (!queue.isEmpty())  
    {  
        Node node = (Node)queue.remove();  
        if (!(node.equals(null))) {s += ""+node.getVal();}  
        if (!(left.equals(null))) {queue.add(node.left);}  
        if (!(right.equals(null))) {queue.add(node.right);}  
    }  
    return s;  
}
</code></pre>

<p>The main problem that I am having is that, when the program gets to a leaf node, it still adds its children to the queue, even though there are no children, just null, so I'll get a queue that has two nulls in front of the actual item in it. I originally had the if statements as (left != null) and such, but that didn't work either. I'm just trying to figure out how to make the program recognize when there aren't any children. What do I need to do?</p>
