Singly Linked List Insertion at End



The steps to insert a node at the end of the list are as follows:
  1. Create new node
  2. Set the new node's link to be Null
  3. Traverse the list, checking to see if the node's next link is Null.
  4. Change the last nodes link from Null to point to the new node.
Insertion at the end of a Singly Linked List is O(n) as the entire list had to be traversed.

Example:
Insert ruler at end of list
  1. Create node ruler
  2. Set ruler.next = null
  3. Traverse the List
    1. Is Head.link = Null? -No
    2. Is paper.link = Null? - No
    3. Is book.link = Null? - No
    4. Is pen.link = Null? - Yes
  4. Set pen.link = ruler
A new node, Ruler was added to the end of the list, and this is the new layout for the Singly Linked List.