程序代码:#include<stdio.h>
#include<malloc.h>
typedef struct Node{
int key;
struct Node *next;
}Node;
Node * Combine(Node * head1,Node * head2)
{
Node * head,*p,*q,*r;
head=(Node *)malloc(sizeof(Node));
head->next=NULL;
r=head;
p=head1->next;
while(p!=NULL)
{
q=(Node *)malloc(sizeof(Node));
q->key=p->key;
q->next=NULL;
r->next=q;
r=r->next;
p=p->next;
}
p=head2->next;
while(p!=NULL)
{
q=(Node *)malloc(sizeof(Node));
q->key=p->key;
q->next=NULL;
r->next=q;
r=r->next;
p=p->next;
}
return head;
}
void show( Node *head)
{
Node *q=head->next;
while(q!=NULL)
{
printf("%d ",q->key);
q=q->next;
}
}
int main()
{
Node * head1=(Node *)malloc(sizeof(Node));
Node * head2=(Node *)malloc(sizeof(Node));
Node *p=head1;
int i;
for(i=1;i<5;i++)
{
Node *q=(Node *) malloc(sizeof( Node));
q->key=i;
q->next=NULL;
p->next=q;
p=p->next;
}
show(head1);
printf("\n");
p=head2;
for(i=3;i<=4;i++)
{
Node *q=(Node *) malloc(sizeof(Node));
q->key=i;
q->next=NULL;
p->next=q;
p=p->next;
}
show(head2);
printf("\n");
Node *head=Combine(head1,head2);
show(head);
printf("\n");
return 0;
}








