Results 1 to 1 of 1
Thread: Binary Search Tree
- 03-06-2009, 04:46 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 2
- Rep Power
- 0
Binary Search Tree
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?
Similar Threads
-
Help loading a Binary Tree from file
By ExplosiveWeasel in forum Java 2DReplies: 16Last Post: 12-17-2008, 01:34 AM -
Binary Search Tree
By michael_mke in forum New To JavaReplies: 3Last Post: 12-04-2008, 02:03 AM -
Binary Search Tree Traversal
By dch414 in forum New To JavaReplies: 2Last Post: 11-07-2008, 12:01 AM -
Can anybody help with cuncurrent binary search tree guys)
By danylo in forum Threads and SynchronizationReplies: 1Last Post: 04-23-2008, 06:22 PM -
Binary Tree Implementation in Java
By Java Tip in forum java.langReplies: 0Last Post: 04-16-2008, 10:35 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks