Hi, I'm trying to make some linked list functions. I found and tried to edit a function which is supposed to delete nth item in a linked list but it deletes (n+2)th item. Can you tell me how to solve this please? Thanks in advance

Here is the function :

ListNode* deleteList(ListNode* node,int n) { ListNode *p, *mycurrent, *pre; p = node; pre = p; mycurrent = node; for(int i = 1; i < n; i++) { mycurrent=mycurrent->next; if(mycurrent->next==NULL) { node = p->next; delete p; return node; } mycurrent = mycurrent->next; p = pre->next; while(mycurrent->next) { p=p->next; mycurrent = mycurrent->next; pre= pre->next; } pre->next = p->next; delete p; return node; } }