Node* insert_node_at_nth_pos(Node *head, int data, int position)
{
/* current node */
Node* cur = head;
/* initialize new node to be inserted at given position */
Node* nth = new Node;
nth->data = data;
nth->next = NULL;
if(position == 0){
/* insert new node at head */
head = nth;
head->next = cur;
return head;
}else{
/* traverse list */
int count = 0;
Node* pre = new Node;
while(count != position){
if(count == (position - 1)){
pre = cur;
}
cur = cur->next;
count++;
}
/* insert new node here */
pre->next = nth;
nth->next = cur;
return head;
}
}