Skip to content

Instantly share code, notes, and snippets.

@abhi1010
Created June 7, 2014 10:47
Show Gist options
  • Save abhi1010/bf9dbb193b4ff84ba3af to your computer and use it in GitHub Desktop.
Save abhi1010/bf9dbb193b4ff84ba3af to your computer and use it in GitHub Desktop.
Delete a Node from Linked List
Node* deleteNode(Node* head,int d)
{
Node* n = head;
if (head->data == d)
{
n = n->next;
delete head;
return n;
}
while (n->next != NULL)
{
if (n->next->data == d)
{
Node* nextNode = n->next->next;
delete n->next;
n->next = nextNode;
}
n = n->next;
}
return head;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment