Data Structure Linked list Question:
Download Questions PDF

Explain the steps to insert data into a singly linked list?

Answer:

Steps to insert data into a singly linked list:-

Insert in middle
Data: 1, 2, 3, 5
1. Locate the node after which a new node (say 4) needs to be inserted.(say after 3)

2. create the new node i.e. 4

3. Point the new node 4 to 5 (new_node->next = node->next(5))

4. Point the node 3 to node 4 (node->next =newnode)

Insert in the beginning

Data: 2, 3, 5

1. Locate the first node in the list (2)

2. Point the new node (say 1) to the first node. (new_node->next=first) Insert in the end

Insert in the end

Data: 2, 3, 5

1. Locate the last node in the list (5)

2. Point the last node (5) to the new node (say 6). (node->next=new_node)

Download Linked list Interview Questions And Answers PDF

Previous QuestionNext Question
Explain the most efficient method to reverse a linked list?How to reverse singly link list?