SLL Algorithm
SLL Algorithm
Algorithm:
5. Delete at Beginning
Algorithm:
1. Check if the list is empty:
If head == NULL, print "List is empty" and terminate the operation.
2. Store the current head node in a temporary pointer (temp).
3. Update head to point to the next node (head->next).
4. Free the memory allocated for the node stored in temp.
5. If the list becomes empty (head == NULL), update tail to NULL.
6. Print "Node deleted from the beginning."
6. Delete at End
Algorithm:
1. Check if the list is empty:
If head == NULL, print "List is empty" and terminate the operation.
2. If the list has only one node:
Free the head node.
Set head and tail to NULL.
Print "Node deleted from the end."
Exit.
3. If the list has more than one node:
Traverse the list to find the second-last node (temp).
While temp->next != tail, move temp to temp->next.
Free the memory for the tail node.
Update tail to point to temp.
Set tail->next to NULL.
4. Print "Node deleted from the end."
Algorithm:
Algorithm:
Algorithm: