Fill in the statements in the following function (called from the public getEntr
ID: 3839939 • Letter: F
Question
Fill in the statements in the following function (called from the public getEntry function above):
private BinaryNode<E> _findNode( BinaryNode<E> node, E targetData )
Here's the algorithm in pseudocode:
IF node is null THEN
return null
ELSE IF targetData < node's data THEN
return a recursive call to the node's left
ELSE IF targetData > node's data THEN
return a recursive call to the node's right
ELSE
return node
HINTS:
see the private _delete method for how to get a node's data
see the private _delete method for how to compare (DON'T use < or >, MUST call compareTo)
Explanation / Answer
_findnode() :
Input : This method takes input as node ( which is of type binary node may conatin many data items ) and target data (required node data).
output : This method returns node (which contains target data )if found , otherwise returns null.
Description :
step 1) Check whether binary node is empty . if binary node is empty then _findNode() method returns null.
-> It shows that either Binary node empty or Binary node doesn't has target node data.
step 2) if Binary node is not empty . and there are nodes in Binary node to check target data node
-> first check node of Binary node with target data node as,
-> if target node data is less than node of Binary node data then do recursive call to the method
_findNode(), input as left node of current Binary node and target data
step 3) if Binary node is not empty . and there are nodes in Binary node to check target data node
-> check node of Binary node with target data node as,
-> if target node data is greater than node of Binary node data then do recursive call to the method
_findNode(), input as right node of current Binary node and target data
step 4) if Binary node is not empty and the cases in step 2) and step 3) are failed then the node is targeted node.
and this node is returned.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.