Delete First Node from Linked List
Advertisements
Delete Front Node from Linked List in C++
Here, we will discuss deleting an element with a specific value from a linked list. There are a few steps to deleting a specific element from the list
- Find the node with the element (if it exists).
- Remove that node.
- Reconnect the linked list.
- Update the link to the beginning (if necessary).
Delete First Node from Singly Linked List
void del_beg() { struct node *temp; temp = start; start = start->next; free(temp); printf("nThe Element deleted Successfully "); }
Follow below steps
- Step 1 : Store Current Start in Another Temporary Pointer
- Step 2 : Move Start Pointer One position Ahead
- Step 3 : Delete temp i.e Previous Starting Node as we have Update the link to the beginning
Store Current Start in Another Temporary Pointer
Syntax
temp = start;
Move Start Pointer One position Ahead
Syntax
start = start->next;
Delete temp i.e Previous Starting Node as we have Update the link to the beginning.
Syntax
free(temp);
Google Advertisment