Searching for a node

Searching for a node is pretty simple. We need to iterate through each node and check whether the target data matches with the node data. If the data is found, the node will be returned; otherwise, it will return FALSE. The implementation looks like this:

    public function search(string $data = NULL) { 
if ($this->_totalNode) {
$currentNode = $this->_firstNode;
while ($currentNode !== NULL) {
if ($currentNode->data === $data) {
return $currentNode;
}
$currentNode = $currentNode->next;
}
}
return FALSE;
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset