Friday, October 16, 2009

Operation 5 – Retrieve Node :

After knowing how to locate a node in the list, we can retrieve data from that node. Retrieve node uses search mode to locate the data in the list. If the data are found, it moves the data to the output area in the calling module and returns true. If they are not found, it returns false. The pseudocode is shown in Algorithm 5.

Algorithm – 5: Retrieve linked list node

algorithm retrieveNode (val list ,

val key ,

ref dataOut )

Retrieves data from a linked list.

Pre list is metadata structure to a valid list

key is target data to be retrieved

dataOut is variable to receive retrieved data

Post data placed in dataOut

-or- error returned if not found

Return true if successful, false if data not found

1 found = searchList (list, pLoc, key)

2 if (found)

1 dataOut = pLoc->data

3 end if

4 return found

end retrieveNode

No comments:

Post a Comment