# 合并两个线性表c 语言,如何用c程序建立两个线性表并把他们合并成一个线性表？...

ryan_gan

#include “stdio.h”

#include “stdlib.h”

#include “malloc.h”

#define NULL 0

struct List

{

int data;

struct List *next;

}List;

struct List * InitList()

{

int d;

scanf(“%d”,&d);

while(d>0)

{

q=(struct List *)malloc(sizeof(struct List));

q->next=NULL;

q->data=d;

p->next=q;

p=p->next;

scanf(“%d”,&d);

}

}

{

struct List *p,*q;

int t;

{

for(q=p->next;q;q=q->next)

{

t=p->data;

p->data=q->data;

q->data=t;

}

}

}

struct List * UniteList(struct List *a,struct List *b)

{

p=a->next;

q=b->next;

while(p&&q)

{

if(p->data>q->data)

{

s->next=q;

q=q->next;

}

else

{

s->next=p;

p=p->next;

}

s=s->next;

}

if(p==NULL)s->next=q;

else s->next=p;

}

{

struct List *p;

printf(“\n\n”);

while(p)

{

printf(“%5d”,p->data);

p=p->next;

}

printf(“\n\n”);

}

void main ()

{

printf(“\n创建链表a：\n\n”);

printf(“\n链表a：”);

system(“pause”);

system(“cls”);

printf(“\n创建链表b：\n\n”);

printf(“\n链表b：”);

system(“pause”);

system(“cls”);

printf(“\n递增排序后的链表a：”);

printf(“递增排序后的链表b：”);