Answered step by step
Verified Expert Solution
Question
1 Approved Answer
DLList common _ ancestors ( const T & val 1 , const T & val 2 ) const { if ( ! contains ( val
DLList commonancestorsconst T & val const T & val const
if containsvalcontainsval
return DLList;
DLList ancestors;
if val val
BSTNode node root;
while node
ancestors.addtotailnodeval;
if val nodeval
node nodeleft;
else if val nodeval
node noderight;
else
break;
else
findCommonAncestorsroot val val ancestors;
return ancestors;
ADD YOUR IMPLEMENTATION HERE
bool BST::findCommonAncestorsBSTNode node, const T& val const T& val DLList& ancestors const
if node
return false;
bool foundInLeft findCommonAncestorsnodeleft, val val ancestors;
bool foundInRight findCommonAncestorsnoderight, val val ancestors;
if foundInLeft && foundInRightnodeval val nodeval val
ancestors.addtotailnodeval;
return true;
return foundInLeft foundInRight nodeval val nodeval val;
where is the error in the above code when i get this error Oops something is wrong with your solution:
Nodes were inserted into the BST in this order:
Your result from commonancestors:
Correct result from commonancestors:
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