Description
本题为完善程序题,仅需提交缺失部分代码,主函数内已经完成其余操作(输入输出、调用函数),仅需完成函数内功能
学习了链表之后,我们来练习链表的删除操作,删除完成后返回新链表的表头指针(方便主函数调用)
Input
共三行,
第一行为链表的长度
第二行一个数列,主函数内自动使用链表存储
第三行为需要删除第几个节点
Output
删除节点后的整个链表
Sample Input 1
5
6 7 8 9 1
3
Sample Output 1
6 7 9 1
Hint
仅需提交函数内缺失代码
如果有表头的话,那就不需要返回。
bool del_node(Node *root, int index)
{
Node *pn, ptmp;
if(root==null || index<1) return false;
pn=root;
while(pn->nxt)
{
index--;
if(index==0)
{
ptmp=pn->nxt;
pn->nxt=ptmp->nxt;
free(ptmp);
return true;
}
pn=pn->nxt;
}
return false;
}