0

I'm having trouble formatting a binary tree. In my program, the tree format should print every output as such:

35
30
29
25
24
20
15

This is the code that I have thus far.

public void treeFormatTraversal(){//begin
		int level = 0;
		if(root !=null)
			treeFormatHelper(root, level);
		else
			System.out.println("\nTree is Empty\n");
	}
	private void treeFormatHelper(TreeNode<T> tree, Integer indentSpaces){
		
		if(tree==null)
			return;
		treeFormatHelper(tree.rightNode,indentSpaces+1);
		for(int x=1;x<indentSpaces;x++)
			System.out.print("\t");
		System.out.printf("%s",tree.data);
		treeFormatHelper(tree.leftNode,indentSpaces+1);
	}

Any help is appreciated on how to implement the display format.

Thanks

1
Contributor
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Iamthecheese
0

------35
---30
------29
25
------24
---20
------15

I meant like this without the dashes. :)

Edited by Iamthecheese: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.