Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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 found

Explanation / 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));

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote