Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

print binary search tree

807600Nov 3 2007 — edited Nov 4 2007
I'm really tired so this is probably a really dumb mistake, but I'm having trouble printing my binary search tree. Here's the method that I made to print(it works fine if I use System.out.println, but I want to use JOptionPane) I'm open to any suggestions as to how to make the code better too. Please let me know if you need to see all of my code

Thanks
public void print() 
	{ 
	JOptionPane.showMessageDialog(null, recprint(root));
	} 
	
	private void recprint(TreeNode p) 
	{ // recursively print the tree 
		 if (p == null) 
	return; 
	recprint (p.left); 
	System.out.print(p.key + "\n"); 
 	recprint (p.right); 
	} 
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 2 2007
Added on Nov 3 2007
10 comments
444 views