Professional Documents
Culture Documents
Sidra Malik
sidra.malik@ciitlahore.edu.pk
Linked Lists
• A linked list is a linear collection of homogenous data
elements, called nodes, where the linear order is
given by means of pointers.
80 X
14 Link 72 Link
temp
temp
Step 1: Update the next link of a new node, to point to the current head node
Insertion at front
temp->data = info; // store data(first field)
temp->next=head; // store the address of the pointer head(second field)
head = temp; // transfer the address of 'temp' to 'head'
Step 1: Update the next link of the current tail node, to point to the new node.
Step 1: Update link of the "previous" node, to point to the new node.
Insertion in Middle
node *temp; // create a temporary node
temp = (node*)malloc(sizeof(node)); // allocate space for node
temp->data = info; // store data(first field)
back
.back .info .next
Double Linked Lists
• Insertion at Front