Use the program below to: Add a recursive method named getDepth() that returns a
ID: 3891837 • Letter: U
Question
Use the program below to:
Add a recursive method named getDepth() that returns an int that is the depth of the deepest node in the tree. Also add a recursive method named getSize() that returns the number of nodes in the tree. Add code to the main program to test your methods.
Write and test a copy constructor for the Binary Search Tree class. A copy constructor takes a reference to a BST and creates a copy. Note that you cannot just copy the root reference. You must go through the original tree and create copies of all the nodes. This is easiest to do with a recursive function that takes a parameter that is a Node. If the Node is null, return null, else return a new node that contains as data a copy of the original Node object, data, and the left and right references refer to copies of the left and right subtrees of the original Node. These copies are returned by recursive calls to the copy function. This is called making a deep copy. Test the constructor by creating a tree, making a copy of it, and then modifying the copy. Print out both the original tree and the copy to show they are actually different trees.
Explanation / Answer
Here are yout methods
And you test code
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.