Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Ex 1 . Common Ancestors Problem Description Write a BST function named common _ ancestors that takes two values of templated type T as arguments:
Ex Common Ancestors
Problem Description
Write a BST function named commonancestors that takes two values of templated type T as arguments:
DLList commonancestorsconst T & val const T & val const
The function should search the BST for these values and return a Doubly Linked List DLList containing the values of the common ancestors of val and val
Here's what the function should do in details:
If both val and val are found in the BST:
The function should return a DLList containing all the nodes that are ancestors of both val and val
If either val or val is not found in the BST:
The function should return an empty DLList.
Examples
Example : Both values found
The function should assume the BST has unique values for each node no duplicate values
val
val
Expected Output: DLList containing node with value the only common ancestor
Example : Both values found
val
val
Expected Output: DLList containing nodes with values and
Example : One or both values not found
valnot in the BST
val
Expected Output: Empty DLList
The function should assume the BST has unique values for each node no duplicate values
Note. You are not allowed to declare any additional data members, but you can define helper functions in the private section of the BST class.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started