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