Write a method called printLeaves that prints to System.out the leaves of a binary tree from right to left. More specifically, the leaves should be printed in the reverse order that they would be printed using any of the standard traversals. If the tree is empty, your method should produce the output "no leaves" . For example, if a variable t refers to reference tree #2, the call of t.printLeaves(); should produce the following output:
leaves: 0 4 9
Add the above method to the IntTree class from this chapter. You may define additional private methods to implement your public method if necessary. Several problem descriptions refer to the following reference binary trees:
public void printLeaves()
{
if(overallRoot == null)
{
System.out.println("no leaves");
}
else
{
System.out.print("leaves: ");
printLeaves(overallRoot);
}
}
private void printLeaves(IntTreeNode root)
{
if(root == null)
return;
if(root.left == null && root.right == null)
{
System.out.print(root.data + " ");
}
else
{
printLeaves(root.left);
printLeaves(root.right);
}
}