listing traversing linked list def traversalhead )curnode head while curnode is not none print curnode data curnode curnode next the list has been accessed the completion of the traversal is determined when curnode becomes nullas illustrated in figure (fafter accessing the last node in the listcurnode is advanced to the next nodebut there being no next nodecurnode is assigned none from the next field of the last node correct implementation of the linked list traversal must also handle the case where the list is empty rememberan empty list is indicated by null head reference if the list were emptythe curnode reference would be set to null in line of listing and the loop would not execute producing the correct result complete list traversal requires (ntime since each node must be accessed and each access only requires constant time searching for node linear search operation can be performed on linked list it is very similar to the traversal demonstrated earlier the only difference is that the loop can terminate early if we find the target value within the list our implementation of the linear search is illustrated in listing listing searching linked list def unorderedsearchheadtarget )curnode head while curnode is not none and curnode data !target curnodecurnode next return curnode is not none note the order of the two conditions in the while loop it is important that we test for null curnode reference before trying to examine the contents of the node if the item is not found in the listcurnode will be null when the end of the list is reached if we try to evaluate the data field of the null referencean exception will be raisedresulting in run-time error remembera null reference does not point to an object and thus there are no fields or methods to be referenced when implementing the search operation for the linked listwe must make sure it works with both empty and non-empty lists in this casewe do not need separate test to determine if the list is empty this is done automatically by checking the traversal reference variable as the loop condition if the list were emptycurnode would be set to none initially and the loop would never be entered the linked list search operation requires (nin the worst casewhich occurs when the target item is not in the list