Search⌘ K

Singly Linked List - Deletion

Explore the process of deleting nodes in singly linked lists with this lesson. Understand how to remove the head node and nodes at any position using pointer adjustments. Gain confidence in handling linked list deletion scenarios and prepare to extend these skills to other linked list types.

Structure

Each node contains a value and a pointer to the next node.

C++
struct Node {
int val;
Node* next;
Node (int val) {
this->val = val;
this->next = NULL;
}
}

Deletion

There are 2 cases:

  • Delete head
  • Delete node at a given position

The worst-case for deleting a node is ...