#include<stdio.h>
#include<stdlib.h>
typedef struct Node
{
int data;
struct Node* next;
}LinkList;
LinkList *CreateLinkList(LinkList *head, int x)//创建新链表
{
LinkList *p, *q;
head = (LinkList*)malloc(sizeof(LinkList));
q=head;
for(int i=0; i<x; i++)
{
p = (LinkList*)malloc(sizeof(LinkList));
scanf("%d",&(p->data));
q->next=p;
q=p;
}
q->next=NULL;
return head;
}
int main()
{
int m,n;
LinkList *p,*L1,*L2;
scanf("m=%d",&m);
L1 = CreateLinkList(L1,m);
getchar();
getchar();
scanf("n=%d",&n);
L2 = CreateLinkList(L2,n);
p=L1;
while(p->next!=NULL)
{
p = p->next;
}
p->next = L2->next;
L1 = L1->next;
while(L1!=NULL)
{
printf("%d ",L1->data);
L1 = L1->next;
}
}
最快合并链表(线性表)
最新推荐文章于 2022-06-06 23:45:00 发布