Answered step by step
Verified Expert Solution
Link Copied!

Question

00
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:

Ex1. Common Ancestors
Problem Description
Write a BST function named common_ancestors that takes two values of templated type T as arguments:
DLList common_ancestors(const T & val1, const T & val2) 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 val1 and val2.
Here's what the function should do in details:
If both val1 and val2 are found in the BST:
The function should return a DLList containing all the nodes that are ancestors of both val1 and val2.
If either val1 or val2 is not found in the BST:
The function should return an empty DLList.
Examples
Example 1: Both values found
The function should assume the BST has unique values for each node (no duplicate values).
val1=4
val2=11
Expected Output: DLList containing node with value 5(the only common ancestor)
Example 2: Both values found
val1=5
val2=19
Expected Output: DLList containing nodes with values 15, and 20
Example 3: One or both values not found
val1=7(not in the BST)
val2=4
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

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions