Created
May 9, 2016 21:03
-
-
Save jianminchen/79dd121f3135769d57088c7d2e9e51fe to your computer and use it in GitHub Desktop.
HackerRank - LinkedList - insert a node at the head of a 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
/* | |
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