两个简单链表的简单链接
程序代码:#include<stdio.h>
#include<malloc.h>
#define LEN sizeof(struct student)
struct student
{
float num;
int score;
struct student *next;
};
struct student *creat_o(void)
{
struct student *p,*p1,*head;
int n=0;
head=(struct student *)malloc(LEN);
p=head;
printf("please input the first node date\n");
scanf("%f%d",&p->num,&p->score);
while(p->next!=NULL)
{
if(p->num!=0)
{
p1=p;
printf("please input the %d date\n",++n);
p=(struct student *)malloc(LEN);
scanf("%f%d",&p->num,&p->score);
p1->next=p;
}
else
p->next=NULL;
}
p1->next=NULL;
return(head);//if no ()
}
struct student *creat_t(void)
{
struct student *p,*p1,*head;
int n=0;
head=(struct student *)malloc(LEN);
p=head;
printf("please input the first node date\n");
scanf("%f%d",&p->num,&p->score);
while(p->next!=NULL)
{
if(p->num!=0)
{
p1=p;
printf("please input the %d date\n",++n);
p=(struct student *)malloc(LEN);
scanf("%f%d",&p->num,&p->score);
p1->next=p;
}
else
p->next=NULL;
}
p1->next=NULL;
return(head);//if no ()
}
int main()
{
struct student *head,*p[3];
p[0]=creat_o(); // can't have 'void' in ()
p[1]=creat_t();
if(p[0]->num>p[1]->num)
{
head=p[1];
while(p[1]->next!=NULL)
p[1]=p[1]->next;
p[1]->next=p[0];
}
else
{
head=p[0];
while(p[0]->next!=NULL)
p[0]=p[0]->next;
p[0]->next=p[1];
}
p[2]=head;
printf("follows are the linked\n");
while(p[2]!=NULL)
{
printf("%0.0f%4d\n",p[2]->num,p[2]->score);
p[2]=p[2]->next;
}
return 0;
}
第一次写的 欢迎大家提出改进意见 谢了









