Question: X 1 X 1 2 2 0 : Complete method countNodes Define a recursive method countNodes ( ) that counts all the nodes in the

X1X1220: Complete method countNodes
Define a recursive method countNodes() that counts all the nodes in the tree. Returns the number of nodes.
Your Answer:
1
int countNodes(BinaryNode root)
2
{
Use these two interfaces to solve this problem.
1
public interface QueueADT {
2
public void clear();
3
public boolean enqueue(E it);
4
public E dequeue();
5
public E frontValue();
6
public int numElements();
7
public boolean isEmpty();
8
}
9
10
interface StackADT {
11
public void clear();
12
public boolean push(E it);
13
public E pop();
14
public E topValue();
15
public int numElements();
16
public boolean isEmpty();
17
}
Write a method to remove all of the elements from the 'queue' (one by one) and add them to a newly created stack (use a StackArray) and push the values in the stack. Return this stack. If queue is null, then just return an empty stack. Make sure you use the interfaces from above.

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