all. BelowThis code is my implementation of "Insertbuilt to insert a node atNode into a specific position inof a linked list"-list. It already passedpasses all the test cases. Could you plz help verify for the codeinterview, but I was wondering about the coding style regarding technique interviewtechniques, and especially the variable name?naming, and any other best-practices you can help with.
Node* InsertNth(Node *head, int data, int position)
{
// Complete this method only
// Do not write main function.
Node * sentinel = new Node();
sentinel->data = -1;
sentinel->next = head;
Node* node = sentinel;
int i = 0;
while (node->next && i < position) {
node = node->next;
i++;
}
Node* preNext = node->next;
Node* newNode = new Node();
newNode->data = data;
newNode->next = preNext;
node->next = newNode;
head = sentinel->next;
delete sentinel;
return head;
}