Hi

I'm using a Binary Search Tree, and outputting it with Pre-order traversal.

My Pre-order traversal code:

public void printPreorder()
{
System.out.println("Preorder");
printPreorder(root, 0);

}


private void printPreorder(BinaryNode t, int n)
{
for(int i = 0; i < n; i++)
{
System.out.print("\t");
}

if (t != null)
{
System.out.println(t.element.toString( ) );
printPreorder(t.left, n+1);
printPreorder(t.right, n+1);
}
}


The traversal code is working correct but there is something wrong with my tabs. The output looks like this:
indicated *tab* where it displays a tab

5
*tab* 2
*tab**tab* 1
*tab**tab**tab**tab**tab**tab**tab* 3
*tab**tab**tab**tab**tab* 4
*tab**tab**tab**tab**tab**tab**tab**tab* 6
*tab**tab**tab* 7


but must actually be:
5
*tab* 2
*tab**tab* 1
*tab**tab* 3
*tab**tab**tab* 4
*tab**tab* 7
*tab* 6


Can someone please help me with my tabs?