#include<stdio.h>
#include<stdlib.h>
struct student
{
int num;
int scroe;
struct student *next;
};
main()
{
struct student *head,*p1,*p2,*p3,*head1,*p4,*p5,*p6,*p7,*p8,*p9;
/*输入第一个链表*/
head = p1 = (struct student*)malloc(sizeof(struct student));
head = NULL;
head -> next = p1;
printf("input date\n");
scanf("%d%d",&(p1 -> num),&(p1 ->scroe));
while((p1 -> num != 0)&&(p1 -> scroe != 0))
{
p2 =(struct student*)malloc(sizeof(struct student));
p1 -> next = p2;
p1 = p2;
scanf("%d%d",&(p1 -> num),&(p1 -> scroe));
}
p1 -> next = NULL;
printf("\n");
p6 = head -> next;
printf("%df",p6->scroe); /*如果不加这几话,下面代文号的printf出来的结果和加这几话会不同。请问这是为什么???win - tc下运行的
/*输入第二个链表*/
head1 = p4 = (struct student*)malloc(sizeof(struct student));
head1 = NULL;
head1 -> next = p4;
printf("input second date\n");
scanf("%d%d",&(p4 -> num),&(p4 -> scroe));
while((p4 -> num != 0)&&(p4 -> scroe != 0))
{
p5 = (struct student*)malloc(sizeof(struct student));
p4 -> next = p5;
p4 = p5;
scanf("%d%d",&(p4 -> num),&(p4 -> scroe));
}
p4 -> next =NULL;
printf("\n");
p7 = head1 -> next;
printf("%d %d",p6->scroe,p7->scroe); /*只是用来作为跟踪p6,p7的标记。
while((p7 -> num != 0)&&(p7 -> scroe != 0))
{
if(p6 -> scroe > p7 -> scroe)
{
p8 = (struct student*)malloc(sizeof(struct student));
p8 -> next = p6 -> next;
p6 -> next = p8;
p8 -> num = p7 -> num;
p8 -> scroe = p7 -> scroe;
p7 = p7 -> next;
p6 = p8 -> next;
}
}
p3 = head -> next;
/*打印出相加完的第一个链表*/
while((p3 -> num !=0)&&(p3 -> scroe != 0))
{
printf("%d %d",p3 ->num,p3 -> scroe);
p3 = p3->next;
printf("\n");
}
getch();
}