c. Given the following algorithm for searching a binary tree (or a portion of th
ID: 3595280 • Letter: C
Question
c. Given the following algorithm for searching a binary tree (or a portion of the algorithm) in real code , be able to fill in the blanks // Define a structure to be used as the tree node struct TreeNode int // Other fields defined here TreeNode *left TreeNode *right; Key; TreeNode *MyTree::SearchTree(int Key) TreeNode *temp - root; // Search for the correct TreeNode while( if(Key Key) temp = ; // Search key comes before this node. else temp ; // Search key comes after this node if (tempNULL) // check for search key not found return ; // Return appropriate value if not found else returrn ; // Return apprlpriate value if foundExplanation / Answer
TreeNode *MyTree::SearchTree(int Key)
{
TreeNode *temp = root;
while( temp!=NULL && Key !=temp->Key )
{
if ( Key < temp->Key)
temp = temp->left;
else
temp = temp->right;
}
if ( temp == NULL)
return NULL;
else
return (DupNode(temp));
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.