10. Delete front node in Linked List
Figure 6. Delete front Node.
Logic:
Take head into one dummy pointer named as front. update head to head->next
Make dummy pointer next to NULL
Deallocate memory of dummy node i.e. free(front).
Main Function code:
head=remove_front(head);
Take head into one dummy pointer named as front. update head to head->next
Make dummy pointer next to NULL
Deallocate memory of dummy node i.e. free(front).
Main Function code:
head=remove_front(head);
display(head);
C function for remove front operation:-
node* remove_front(node* head)
{
if(head == NULL)
return NULL;
node *front = head; //dummy pointer to head
head = head->next; // move head to next node
front->next = NULL; //break pointer link of updated head
free(front); // free allocated memory
return head;
}
No comments:
Post a Comment