Question: To class Tree, add the following methods: 1 - nodesInLevel ( int x ) : it returns number of nodes in a specific level x
To class Tree, add the following methods:
nodesInLevelint : it returns number of nodes in a specific level
for example in this tree, nodesInLevel is assuming that root is in
level Hint: this method should call a recursive method.
ancestors int k: it prints all ancestor of the node with key starting
by the parent toward the root.
For example ancestors it prints:
Hint: you need to use a stack.
printByLevel which prints all nodes in the tree level by level, it prints all nodes in a specific level
before moving to the nodes at the next depth level. For example this tree should be printed as
follows:
Hint: you need to use a queue.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
