Modifying a Linked List
Insert a new element at the beginning:
insertLL(L,d):
| Input linked list L, value d
| Output L with d prepended to the list
|
| new=makeNode(d) // create new list element
| new.next=L // link to beginning of list
| return new // new element is new head
|
Time complexity: O(1)
|