Created
December 2, 2014 01:02
-
-
Save dgodfrey206/befa43f58bf6e573bfc5 to your computer and use it in GitHub Desktop.
Deleting a node from a 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
Node* DeleteNode(Node*& head, int value) | |
{ | |
Node** ptr = &head, *next; | |
while (*ptr && (*ptr)->data != value) | |
ptr = &(*ptr)->next; | |
if (!*ptr) | |
return NULL; | |
next = (*ptr)->next; | |
delete *ptr; | |
*ptr = next; | |
return head; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment