Singly Linked List - Insertion
In this lesson, we'll learn how to insert an element in a singly linked list.
We'll cover the following...
Structure
Each node contains a value and a pointer to the next node.
Press + to interact
struct Node {int val;Node* next;Node (int val) {this->val = val;this->next = NULL;}}
Insertion
There are 3 cases:
- Insert at beginning
- Insert at some given position
- Insert at end
The worst-case complexity of insertion in a linked list is ...