Professional Documents
Culture Documents
Linear by Starting
Linear by Starting
In a singly linked list, linear search can be performed by starting at the head of the list and iterating
through each node until the target element is found or the end of the list is reached. If the target
element is found, the search is successful, and the index of the element is returned. Otherwise, the
search continues until the end of the list is reached.
Example;
Class Node:
def_init_ (self, data):
Self.head=data
Self.head=None
Class LinkedList:
def_init_(self):
self. head=None
def_Linear Search (self, target);
Current = self. head
While current is not None:
If current. Data==target:
return current
current=current. Next
Return None