Question: removeLeaves Implement a method that removes the leaf nodes from an IntTree. ( Remember that a leaf node is one that has empty left and

removeLeaves
Implement a method that removes the leaf nodes from an IntTree. (Remember that a leaf node is one that has empty left and right subtrees.) If a variable tree refers to the first tree below, the removeLeaves(tree) should remove the four leaves from the tree (the nodes with data values 1,4,6, and 0) leaving the next tree below.
A second call on the method would eliminate the two leaves in this tree (the nodes with data values 3 and 8), shown in the third tree below.
A third call would eliminate the one leaf with data value 9, and a fourth call would leave an empty tree because the previous tree was exactly one leaf node.
If your method is called on an empty tree, the method does not change the tree because there are no nodes of any kind (leaf or not).
Example removeLeaves tree

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!