Iteration over Linked Lists (cont)
Check if list contains an element:
inLL(L,d):
| Input linked list L, value d
| Output true if d in list, false otherwise
|
| p=L
| while p≠NULL do
| | if p.value=d then // element found
| | return true
| | end if
| | p=p.next
| end while
| return false // element not in list
|
Time complexity: O(|L|)
|