Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created May 9, 2016 21:03
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/79dd121f3135769d57088c7d2e9e51fe to your computer and use it in GitHub Desktop.
Save jianminchen/79dd121f3135769d57088c7d2e9e51fe to your computer and use it in GitHub Desktop.
HackerRank - LinkedList - insert a node at the head of a linked list
/*
Insert Node at the begining of a linked list
Initially head pointer argument could be NULL for empty list
Node is defined as
struct Node
{
int data;
struct Node *next;
}
return back the pointer to the head of the linked list in the below method.
*/
Node* Insert(Node *head,int data)
{
Node* newHead = new Node();
newHead->data = data;
newHead->next = head;
return newHead;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment