Created
June 7, 2014 10:47
-
-
Save abhi1010/bf9dbb193b4ff84ba3af to your computer and use it in GitHub Desktop.
Delete a Node from Linked List
This file contains 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 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