#include <stdio.h>
#include <stdlib.h>
typedef struct node{
int date;
struct node *next;
}body;
body *table()
{
int i,a;
body *head,*p1,*p2;
head=NULL;
for(i=0;;i++)
{
p1=(body*)malloc(sizeof (body));
scanf("%d",&a);
p1->date=a;
if(head==NULL)
{
head=p1;
p2=p1;
}
else
{
p2->next=p1;
p2=p1;
}
if(getchar()=='\n')
break;
}
p2->next=NULL;
return head;
}
//合并两个链表
body *add(body *add1,body *add2)
{
body *temp;
if(add1==NULL)
{
return add2;
}
else
{
if(add2!=NULL)
{
for(temp=add1;temp->next!=NULL;temp=temp->next); //遍历add1到最后一个指针
temp->next=add2; //add1最后一个指针只向add2第一个元素
}
}
return add1;
}
void input2()
{
body *add1,*add2,*q;
add1=table();
add2=table();
q=add(add1,add2); //有疑问q,还有上面为什么add要加*
while(q)
{
printf("%d ",q->date);
q=q->next;
}
}
int main()
{
input2();
return 0;
}
#include <stdlib.h>
typedef struct node{
int date;
struct node *next;
}body;
body *table()
{
int i,a;
body *head,*p1,*p2;
head=NULL;
for(i=0;;i++)
{
p1=(body*)malloc(sizeof (body));
scanf("%d",&a);
p1->date=a;
if(head==NULL)
{
head=p1;
p2=p1;
}
else
{
p2->next=p1;
p2=p1;
}
if(getchar()=='\n')
break;
}
p2->next=NULL;
return head;
}
//合并两个链表
body *add(body *add1,body *add2)
{
body *temp;
if(add1==NULL)
{
return add2;
}
else
{
if(add2!=NULL)
{
for(temp=add1;temp->next!=NULL;temp=temp->next); //遍历add1到最后一个指针
temp->next=add2; //add1最后一个指针只向add2第一个元素
}
}
return add1;
}
void input2()
{
body *add1,*add2,*q;
add1=table();
add2=table();
q=add(add1,add2); //有疑问q,还有上面为什么add要加*
while(q)
{
printf("%d ",q->date);
q=q->next;
}
}
int main()
{
input2();
return 0;
}