Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created May 9, 2016 21:10
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/957d2025fd310a9e59fb88fe8766e0de to your computer and use it in GitHub Desktop.
Save jianminchen/957d2025fd310a9e59fb88fe8766e0de to your computer and use it in GitHub Desktop.
HackerRank - LinkedList - insert a node at tail of linked list
/*
Insert Node at the end of a linked list
head pointer input could be NULL as well for empty list
Node is defined as
struct Node
{
int data;
struct Node *next;
}
*/
Node* Insert(Node *head,int data)
{
Node* newNode = new Node();
newNode->data = data;
if(head==NULL)
return newNode;
Node* nextNode = Insert(head->next, data);
head->next = nextNode;
return head;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment