Question: Create a public class called YourBinaryTree that extends BinaryTree, override protected int countEqualToEitherChild ( ), and return the count as described above. A portion of

Create a public class called YourBinaryTree that extends BinaryTree, override protected int countEqualToEitherChild ( ), and return the count as described above. A portion of the BinaryTree class that you are extending is shown below for reference.

Follow our usual guidelines for writing recursive functions:

1. Identify the base case

2. Make the problem smaller at each step

3. Combine results appropriately

That—as usual—you will want sum to act as a wrapper and call a private method private int countEqualToEitherChild (Node current) that starts the recursion on the root node. Note also that the nodes in the tree are Objects and so you should test for equality appropriately.
public class BinaryTree (

protected class Node {

protected Object value;

protected Node right;

protected Node left;

Node(Object setValue) {

value = setValue; }

}

protected Node root;

// Remainder omitted for brevity

}

Step by Step Solution

3.32 Rating (146 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To create a public class YourBinaryTree that extends BinaryTree and overrides the countEqualToEitherChild method follow these steps Step 1 Define the ... View full answer

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 Programming Questions!