#include <stdio.h>
#include <malloc.h>
struct student
{
int num;
char name[10];
struct student *next;
};
void main()
{ void print(struct student *head);
struct student *creat();
struct student *solve(struct student *head_a,struct student *head_b);
struct student *head,*head_a,*head_b;
head_a=creat();
head_b=creat();
head=solve(head_a,head_b);
print(head);
}
struct student *creat()
{
struct student *head,*p,*p1;
p1=(struct student *)malloc(sizeof(struct student));
head=p=p1;
printf("输入学号和姓名0停止接收数据\n");
printf("请输入学生学号和姓名:");
scanf("%d %s",&p->num,&p->name);
while(p->num!=0)
{
printf("请输入学生学号和姓名:");
p1->next=p;
p1=p;
p=(struct student *)malloc(sizeof(struct student));
scanf("%d %s",&p->num,&p->name);
}
p1->next=NULL;
return head;
}
struct student *solve(struct student *head_a,struct student *head_b)
{
struct student *p,*p1,*t;
p=p1=head_a;
t=head_b;
while(p!=NULL)
{
t=head_b;
while(t->next!=NULL&&(t->num!=p->num))
{
t=t->next;
}
if(t->num==p->num)
{
if(p==head_a)
{
head_a=head_a->next;
p1=p=head_a;
}
else
{
p1->next=p->next;
p=p->next;
}
}
else
{
p1=p;
p=p->next;
}
}
return head_a;
}
void print(struct student *head)
{
struct student *p;
while(p!=NULL)
{
printf("%d %s\n",p->num,p->name);
p=p->next;
}
}
帮我看看我哪里写错了。。。。。答的好有追加~