Search⌘ K

Singly Linked List Insertion

Explore the three main insertion methods in singly linked lists: at the head, at the tail, and at the nth node. Understand how to implement insertion at the head in C++ with efficient O(1) time complexity and prepare for further operations in linked list management.

In this lesson, we are going to briefly explain the basic operations which were discussed in the previous lesson. The three types of insertion strategies used in Singly linked-list are:

  1. Insert at Head
  2. Insert at Tail
  3. Insert at the N-th index

Insertion at Head #

This type of insertion means that we want to insert a new element as the first element of the list. As a result, the head pointer will point to the newly​ added node, whose nextElement, in turn, will point to the node previously pointed by the head or null value.

Insert at Tail #

This type of insertion means that we want to insert a new element as the last element of the list. The original tail element of the list has a nextElement pointer that points to NULL. To insert a new tail node, we have to point the nextElement pointer of the previous tail ...