Created
July 20, 2012 04:52
-
-
Save nikmis/3148769 to your computer and use it in GitHub Desktop.
Delete Node from Singly Linked List
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| typedef struct list | |
| { | |
| int item; | |
| struct list *next; | |
| } list; | |
| /* l - Head of the list | |
| * node - Node to be deleted from the list. | |
| */ | |
| void listDeleteByNode(list **l, list *node) | |
| { | |
| if(emptyList(*l)) | |
| return; | |
| list *n = node->next; | |
| /* Check if there's only one node in the list */ | |
| if(emptyList(n)) | |
| { | |
| *l = n; | |
| free(node); | |
| } | |
| else | |
| { | |
| node->item = n->item; | |
| node->next = n->next; | |
| free(n); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment