Write a method called sum that returns the sum of the data values stored in the tree.
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:
Implementation of sum method:
public int sum()
{
return sum(overallRoot);
}
private int sum(IntTreeNode root)
{
if(root == null)
{
return 0;
}
else
{
return root.data + sum(root.left)
+ sum(root.right);
}
}