第1个回答 2013-03-29
#include <stdio.h>
#include <stdlib.h>
#define null 0
typedef struct LNode
{
int data ;
struct LNode *next ;
}LNode , *LinkList;void CreateList_L(LinkList L,int n)
{
int i;
LinkList p;
for(i=n;i>0;--i)
{
p=(LinkList)malloc(sizeof(LNode));
printf(" input numbers: \n");
scanf("%d",&p->data);
p->next=L->next;
L->next=p;
}
}
main()
{
int n1,n2;
LinkList La,Lb,Lc,pa,pb,pc;
printf("input the n1:");
scanf("%d",&n1);
printf("input the n2:");
scanf("%d",&n2);
La=(LinkList)malloc(sizeof(LNode));
La->next=null;
CreateList_L(La,n1);
Lb=(LinkList)malloc(sizeof(LNode));
Lb->next=null;
CreateList_L(Lb,n2);
Lc=(LinkList)malloc(sizeof(LNode));
Lc->next=null;
pa=La->next;
pb=Lb->next;
Lc=pc=La;
while(pa&&pb)
{
if(pa->data<=pb->data)
{
pc->next=pa;
pc=pa;
pa=pa->next;
}
else
{
pc->next=pb;
pc=pb;
pb=pb->next;
}
}
pc->next=pa?pa:pb;
pc=La->next;
while(pc)
{
printf("%d",pc->data);
pc=pc->next;
}
}