Computer Science, asked by amitasundas1137, 1 year ago

How to write an actual algorithm for inserting an element in a linked list?

Answers

Answered by karinakaria
0
The new node is always added before the head of the given Linked List. And newly added node becomes the new head of the Linked List. For example if the given Linked List is 10->15->20->25 and we add an item 5 at the front, then the Linked List becomes 5->10->15->20->25. Let us call the function that adds at the front of the list is push(). The push() must receive a pointer to the head pointer, because push must change the head pointer to point to the new node (See this)



Following are the 4 steps to add node at the front.

Similar questions