Linked List Insertion and Deletion Program

Program for Singly Linked List Insertion and Deletion in C++

Lets try to understand how we can do Insertion and deletion Operations on a Linked List in C++. We will look at most effective methods to do so.

Linked List

We will look at all different methods to insert and delete in the Linked List.

Make sure that you are acquainted with what Linked List is, all terminologies like

  • head
  • tail
  • node
  • data
  • pointer
  • next etc.

Structure of the Linked List

Insertion in Linked List in C++

We will look at three different methods –

  • Method 1: Linked List Insertion using Struct
  • Method 2: Linked List Insertion using class (without class methods)
  • Method 3: Linked List Insertion using class (with class methods)

Insertion Positions

Insertion can be done at the following positions, we will write separate methods for each to demonstrate all possible variations –

  • At start (Default)
  • At last
  • After a certain Node
Singly Linked List Insertion and Deletion in C++ img1
Singly Linked List Insertion and Deletion in C++ img2
Singly Linked List Insertion and Deletion in C++ img3

Output

15 10 5 100 20 25 30 35 

Deletion in Linked List in C++

Again, we will look at three different methods –

  • Method 1: Linked List deletion using Struct
  • Method 2: Linked List deletion using class (without class methods)
  • Method 3: Linked List deletion using class (with class methods)

Insertion Positions

Deletion can be done at the following positions, we will write separate methods for each to demonstrate all possible variations –

  • At start (Default)
  • At last
  • After a certain Node
linked list insertion and deletion program in c++ part1
linked list insertion and deletion program in c++ part2
linked list insertion and deletion program in c++ part3

Output

70 60 50 40 30 20 10

Value Deleted: 70
60 50 40 30 20 10

Value Deleted: 10
60 50 40 30 20

Value deleted: 30
60 50 40 20

Value Deleted: 60
50 40 20

Enter valid position
Enter valid position

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription

Singly Linked List

  • Introduction to Linked List in Data Structure
    Click Here
  • Linked List in –
    C | C++ | Java
  • Singly Linked List in –
    C | C++ | Java
  • Insertion in singly Linked List –
    C | C++ | Java
  • Insertion at beginning in singly Linked List  –
    C | C++Java
  • Insertion at nth position in singly Linked List  –
    C | C++Java
  • Insertion at end in singly Linked List  –
    C | C++Java
  • Deletion in singly Linked List  –
    C | C++Java
  • Deletion from beginning in singly linked list :
    C | C++ | Java
  • Deletion from nth position in singly linked list :
    C | C++ | Java
  • Deletion from end in singly linked list :
    C | C++ | Java
  • Linked List Insertion and Deletion –
    C | C++Java
  • Reverse a linked list without changing links between nodes (Data reverse only) –
    C | C++Java
  • Reverse a linked list by changing links between nodes –
    C | C++Java
  • Print reverse of a linked list without actually reversing –
    C |C++Java
  • Print reverse of a linked list without actually reversing –
    C |C++Java
  • Insertion in the middle Singly Linked List –
    C | C++Java
  • Insertion in a Sorted Linked List –
    C | C++Java
  • Delete alternate nodes of a Linked List –
    C | C++Java
  • Find middle of the linked list –
    C | C++Java
  • Reverse a linked list in groups of given size –
    C | C++Java
  • Find kth node from end of the linked list –
    C | C++Java
  • Append the last n nodes of a linked list to the beginning of the list –
    C | C++Java
  • Check whether linked list is palindrome or not –
    C | C++Java
  • Fold a Linked List –
    C | C++Java
  • Insert at given Position –
    C | C++Java
  • Deletion at given Position –
    C | C++Java

Singly Linked List

  • Introduction to Linked List in Data Structure
  • Linked List in – C | C++ | Java
  • Singly Linked List in – C | C++ | Java
  • Insertion in singly Linked List – C | C++ | Java
    • Insertion at beginning in singly Linked List  – C | C++Java
    • Insertion at nth position in singly Linked List  – C | C++Java
    • Insertion at end in singly Linked List  – C | C++Java
  • Deletion in singly Linked List  – C | C++Java
    • Deletion from beginning in singly linked list : C | C++ | Java
    • Deletion from nth position in singly linked list : C | C++ | Java
    • Deletion from end in singly linked list : C | C++ | Java
  • Reverse a linked list without changing links between nodes (Data reverse only) – C | C++Java
  • Linked List Insertion and Deletion – C | C++Java
  • Reverse a linked list by changing links between nodes – C | C++Java
  • Linked List insertion in the middle – C | C++Java
  • Print reverse of a linked list without actually reversing – C |C++ | Java
  • Search an element in a linked list – C | C++Java
  • Insertion in a Sorted Linked List – C | C++Java
  • Delete alternate nodes of a Linked List – C | C++Java
  • Find middle of the linked list – C | C++Java
  • Reverse a linked list in groups of given size – C | C++Java
  • Find kth node from end of the linked list – C | C++Java
  • Append the last n nodes of a linked list to the beginning of the list – C | C++Java
  • Check whether linked list is palindrome or not – C | C++Java
  • Fold a Linked List – C | C++Java
  • Insert at a given position – C | C++Java
  • Delete at a given position – C | C++Java