//查找单向链表的第n个节点
#include <stdio.h>
PLAYER *Findnode(PLAYER *head, int index)
{
PLAYER *Pt = head;
int i = 1;
while(i < index && Pt!=NULL)
{
Pt = Pt->next;
i++
}
return Pt;
}
//向单项链表的某节点后插入一个节点
PLAYER *insert2(PLAYER *head,int index)
{//要插入pt
PLAYER *prept,*pt;
pt = (PLAYER*)malloc(sizeof(PLAYER));
scanf("%...",&...);
prept = Findnode(head,index)
if(prept != NULL)
{
pt->next = prept->next;//要插入的下一节点的地址储存在上一节点的指针域当中,故将此地址(也就是prept->next)赋给要插入的pt的指针域中
prept->next = pt;//链接前一节点
}
return head;
}
链表的查找和增加
最新推荐文章于 2022-10-03 11:12:19 发布