#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
char date;
struct node *next;
}List;
void InitLink(List*head)//添加新的结点
{
List *p,*q;
int n,i;
p=head;//p先指向头结点
scanf("%d",&n);
for(i=0;i<n;i++)
{
q=(List*)malloc(sizeof(List));//每次都需要动态分配空间
q->next =NULL;
scanf(" %c",&q->date);//前面有个空格
p->next = q;
p=q;
}
p->next =NULL;
}
void Print(List *head)//输出
{
List *q;
q=head->next;
while(q!=NULL)
{
printf("%c ",q->date);
q=q->next;
}
}
void merge(List*head1,List *head2)//链接两个链表
{
List* p;
p=head1;
while(p->next!=NULL)//遍历找到尾部
{
p=p->next;
}
p->next = head2->next;//将尾部和第二个链表的头结点的后一个
}
int main()
{
List *head1,*head2;//两个头结点
head1 = (List*)malloc(sizeof(List));
head1->next =NULL;
InitLink(head1);
head2 = (List*)malloc(sizeof(List));
head2->next =NULL;
InitLink(head2);
merge(head1,head2);
Print(head1);
return 0;
}
版权声明:本文为savokii原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。