C语言中删除链表中的结点问题

来源:百度知道 编辑:UC知道 时间:2024/06/07 06:22:45
建立两个链表head1,head2,每个链表包括一个号码,在head1中删除号码和head2中一样的,我自己写了一个,但是总是删不了,请高手帮忙
#define null 0
#define len sizeof(struct student)
struct student
{
int num;
struct student *next;
};
int n;
struct student *creat()
{
struct student *head,*p1,*p2;
head=null;
printf("please input the link:");
p1=p2=(struct student*)malloc(len);
scanf("%d",&p1->num);
while(p1->num!=0)
{
n=n+1;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student*)malloc(len);
scanf("%d",&p1->num);

}
p2->next=null;
return(head);
}
struct student *del(struct student *head1,struct student *head2)
{
struct student *p,*q,*k;
p=head1;
k=head2;
while(k->next!=null)
{
while((p->num!=k->num)&&(p->next!=null))
{q=p;p=p->next;}

在del 函数中应该返回一个head1

我这里有个链表的建立 添加 删除 输出 的代码 给楼主看看吧 希望可以帮上你的忙 详细代码http://www.cfans8.cn/article.asp?id=870 如果楼主觉得这个网站不错 请推荐给你的朋友 多谢