Insertion in Linked List in Linked Lists
Insertion in Linked List in Linked Lists
Now, suppose we have a linked list 1 -> 2 -> 3 and we want to insert 4 at
the beginning. We can then follow these steps:
2. Add the head of the existing linked list as the next of newNode .
3. Then set the head variable to the newNode , as the newNode is our new
head.
Implementation
To implement insertion operation, we have to create a new class LinkedList
and create a new method insertFront in it.
https://www.codechef.com/learn/course/linked-lists/LINKEDLIST01/problems/LINK01P02 1/1