Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created May 9, 2016 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/d0a360f5a5a4be3b6d94e09d6bd0f266 to your computer and use it in GitHub Desktop.
Save jianminchen/d0a360f5a5a4be3b6d94e09d6bd0f266 to your computer and use it in GitHub Desktop.
HackerRank - LinkedList - delete a node
/*
Delete Node at a given position in a linked list
Node is defined as
struct Node
{
int data;
struct Node *next;
}
*/
Node* Delete(Node *head, int position)
{
if(head==NULL)
return NULL;
if(position == 0)
return head->next;
Node* newHead = Delete(head->next, position-1);
head->next = newHead;
return head;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment