Insert a node at a specific position in a Linked List
This is how I would have done it:

Node* InsertNth(Node *head, int data, int position)
{
    // Use a sentinel as this leads to simpler code
    // and no need to test for the empty list case.
    Node sentinel{-1, head};

    // Find the position we want to insert in.
    // Note: If there are less than `position` elements then
    //       the new element will be added to the end.
    Node* current = &amp;sentinel;
    for(; position != 0 &amp;&amp; current-&gt;next;--position, current = current-&gt;next)
    {}

    // Create the new Node and insert it into the chain.
    Node* newNode = new Node{data, current-&gt;next};
    current-&gt;next = newNode;

    // Update head.
    // In the case of null list or inserting at position 0
    // this will do something. Otherwise this is a no-op.
    head = sentinel.next;

    return newNode;
}


Notes:


Make notes of assumptions you have made in the comments.
I like the for() expression over the while() expression.
It expresses my intent more clearly (ie that I am just chaining along the list).
No need to dynamically create the sentinel. By declaring it on the stack. It works better.
I have assumed node has a reasonable constructor to make the code cleaner.