Skip to content

Instantly share code, notes, and snippets.

@dgodfrey206
Created December 2, 2014 01:02
Show Gist options
  • Save dgodfrey206/befa43f58bf6e573bfc5 to your computer and use it in GitHub Desktop.
Save dgodfrey206/befa43f58bf6e573bfc5 to your computer and use it in GitHub Desktop.
Deleting a node from a singly linked list
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