# include<stdio.h>
# include<stdlib.h>
#include<malloc.h>
# define LEN sizeof(struct student)
struct student
{long num;
float score;
struct student *next;
};
struct student *creat(int x) **创建链表的函数
{ int i;
struct student *head;
struct student *p1,*p2;
p1=p2=(struct student *) malloc (LEN);
scanf("%ld,%f",&p1->num,&p1->score);
head=NULL;
i=0;
while(i<x)
{ i=i+1;
if(i==1){head=p1; p2=p1;}
else
{p1=(struct student *)malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);
p2->next=p1;
p2=p1;}
}
p2->next=NULL;
return(head);
}
void print(struct student *head) **打印函数
{struct student *p;
p=head;
while(p!=NULL)
{printf("%ld,%f\n",p->num,p->score);
p=p->next;
}
}
struct student *merge(struct student *ha,struct student *hb) **让两个表升序 ** 排列
{struct student *hc;
struct student *pc,*p1,*p2;
p1=ha;p2=hb;
if(ha->num < hb->num)
{hc=ha;pc=p1;p1=p1->next;}
else{hc=hb;pc=p2;p2=p2->next;}
do{ if(p1->num < p2->num)
{pc->next=p1;pc=p1;p1=p1->next;}
else{pc->next=p2;pc=p2;p2=p2->next;}
}
while(p1!=NULL && p2!=NULL);
if(p1==NULL) pc->next=p2;
else if(p2==NULL) pc->next=p1;
return(hc);
}
void main() **主函数
{struct student *creat(int);
void print(struct student *);
struct student *merge(struct student *,struct student *);
struct student *hA,*hB,*hC;
int m,n;
printf("Input the No of A line:\n");
scanf("%d",&m);
printf("\nInput the A records:\n");
hA=creat(m);
printf("The A results are:\n");
print(hA);
printf("Input the No of B line:\n");
scanf("%d",&n);
printf("\nInput the B records:\n");
hB=creat(n);
printf("The B results are:\n");
print(hB);
hC=merge(hA,hB);
printf("\n\nThe results are :\n"); 我想用C语言的方法不用数据结构上的知识
print(hC); 谢谢了啊
}