Explain the steps to insert data into a singly linked list?
Submitted by: AdministratorSteps 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)
Submitted by: Administrator
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)
Submitted by: Administrator
Read Online Data Structure Linked list Job Interview Questions And Answers
Top Data Structure Linked list Questions
☺ | Suppose In an integer array, there is 1 to 100 number, out of one is duplicate, how to find? |
☺ | What is circular linked list? |
☺ | Explain linked list using C++ with an example? |
☺ | Explain the steps to insert data into a singly linked list? |
☺ | Explain how to find 3rd element from end in a linked list in one pass? |
Top Data Structure Categories
☺ | Data Center Manager Interview Questions. |
☺ | Sort And Searching Interview Questions. |
☺ | Creative UI/UX Designers Interview Questions. |
☺ | Data Structure Linked list Interview Questions. |
☺ | Data Structure Arrays Interview Questions. |