Question: use java to write Find the Path To Root from a given tree node. Here, you will be creating a recursive method which is a
use java to write
Find the Path To Root from a given tree node.
Here, you will be creating a recursive method which is a specialized kind of find. You will be given an element in the tree to find, and once found, you will need to create an iterator which can traverse the elements along the path from the found element to the root of the tree. So, you will find the path to root for the node given as a parameter.
This method will be added to the LinkedBinaryTree.java file, and has the following header:
public Iterator pathToRoot(T targetElement) throws ElementNotFoundException{
Hint: You will need to create a recursive helper method, pathToRootAgain, as you did with the findAgain method.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
