Question: (Include your modified BinaryTree.java source code file in your homework solution zip archive) Add a method int getSizeO to Binary Tree that returns the size

 (Include your modified BinaryTree.java source code file in your homework solution

(Include your modified BinaryTree.java source code file in your homework solution zip archive) Add a method int getSizeO to Binary Tree that returns the size of the binary tree, where the size of the tree is defined to be the number of nodes. Here is how I want you to implement this method. Write a local class (see Week3 Objects and Classes II Section 2 in method pablic int getSize) named Counter which implements the BinaryTree Visitor visit (pData: E): void m Count: int +Counter(): ctor +getCount): int +visit (pData: E): void The Counter constructor initializes the counter variable mCoant to 0, and the Coanter.visit) method will be called each a time a node is visited either from BinaryTree.traverse(int, Node, BinaryTreeVisitor) or BinaryTree traverseLevelOrdeT(Node, BinaryTreeVisitor) depending on whether you performed a level order traversal or one of the three other types of traversals as described below. Within Counter.visit), we simply increment mCount to count the node as visited Once the local class is completed, we can count the nodes in the tree by performing a traversal (it does not matter which type of traversal we perform because each node will be visited during the traversal; the order in which we visit them does not matter for this application). To perform the traversal write: public int getSize() I // Implement 1local class named Counter here // Create a Counter object to count the nodes Counter counter = new Counter(); // I have chosen to perform a level order traversal, but try the other ones to verify they work // the same way as well, e.g. , traverse (PRE ORDER, counter. travers (LEVEL_ORDER, counter); // After we finish the traverse, Counter.mCount is equal to the number of nodes visited, which // is the size of the tree return counter.getCountO

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!