Solution #1: Store the address of the next node in a temporary pointer. Copy the contents of the next node in the given node and delete the next node. Here is the code,
Also note that this approach is not possible for deleting the last node.
void deleteArbitNode(node* lptr) { node* temp = lptr->next; lptr->data = lptr->next->data; lptr->next = lptr->next->next; free(temp); }
Also note that this approach is not possible for deleting the last node.
1 comment:
What if the next node is NULL?
Post a Comment