ListNode *deleteNode(ListNode *head, int i, int k)
{
//输入合法性检查,不能小于0,也不能i和k都为0
if (i < 0 || k < 0 || (k + i) == 0))
return head;
ListNode *newHead = (ListNode *)malloc(sizeof(ListNode));
newHead->next = head;
ListNode *pre = newHead;
ListNode *tmp;
int n;
//向后移动i + k -1次指向第i + k - 1个结点
for (n = 0; n < (k + i - 1) && pre->next != NULL; n++)
pre = pre->next;
//如果总共无k + i -1个结点则无需删除直接返回
if (n < (k + i - 1))
{
free(newHead);
return head;
}
//tmp指向第i + k个结点
tmp = pre->next;
//删除第i + k个结点
pre->next = pre->next->next;
free (tmp);
//返回链表的头结点
tmp = newHead->next;
free(newHead);
return tmp;
}
数据结构吗?用类高级语言回答就可以了?还是需要具体语言