第一行有两个用空格隔开的整数n和m,分别表示a和b两个链表中的节点个数。保证n和m均不超过100。
之后的n行每行有两个用空格隔开的整数,分别表示一个学生的学号和成绩。
最后的m行每行有两个用空格隔开的整数,分别表示一个学生的学号和成绩。
a和b两个链表中的节点并不一定按照学号顺序排列。保证a链表中学号各不相同,b链表中学号各不相同。
#include <stdio.h>
#include <stdlib.h>
typedef struct Stu
{
int num;
int score;
struct Stu *next;
}stu;
stu *creat(int n)//建立具有n个节点的链表
{
stu *p,*head,*q;
int i;
head=(stu *)malloc(sizeof(stu));
for(i=0;i<n;i++)
{
p=(stu *)malloc(sizeof(stu));
scanf("%d%d",&p->num,&p->score);
p->next=NULL;
if(i==0)
{
head->next=p;
}
else
q->next=p;
q=p;
}
return head;
}
int count(stu *head)//统计链表中节点个数
{
stu *p;
int n=0;
p=head->next;
while(p!=NULL)
{
p=p->next;
n++;
}
return n;
}
void print(stu *head)//输出链表
{
stu *p;
p=head->next;
while(p!=NULL)
{
printf("%d %d\n",p->num,p->score);
p=p->next;
}
}
stu *delelinst(stu *heada,stu *headb)//删除链表中学号相同的结点
{
stu *pa,*qa,*pb,*qb;