#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <math.h>
#define OVERFLOW 0
#define OK 1
//allocation two lists
typedef struct student
{
int num;
struct student *next;
}node,*slist;
slist creat(int n)
{
slist h,p,q;
int a;
h = NULL;
printf("input the integers:\n");
for(int i=0; i<n; i++)
{
scanf("%d", &a);
p = (slist)malloc(sizeof(node));
p->num = a;
p->next = NULL;
if(h == NULL)
{
h = p;
q = p;
}
else
{
q->next = p;
q = p;
}
}
return h;
}
slist list_merge(slist p1, slist p2)
{
if(p1 == NULL)
return p2;
slist t = p1;
while(t->next != NULL)
{
t = t->next;
}
t->next = p2;
return p1;
}
int main()
{
slist h1,h2,s;
int n1,n2;
printf("please input two counts list:\n");
scanf("%d%d",&n1, &n2);
h1 = creat(n1);
h2 = creat(n2);
s = list_merge(h1,h2);
while(s != NULL)
{
printf("%d ", s->num);
s = s->next;
}
return 0;
}
合并链表
最新推荐文章于 2024-05-01 16:00:54 发布