#include<stdio.h>
#include<stdlib.h>
/*实验三*/
typedef struct Node{
int num;
struct Node *next;
}node,*Linklist;
node *StartList(node *head)
{
head=(node*)malloc(sizeof(node));
head->next=NULL;
return head;
}
void insert_num(node *A,int x) /*排序函数*/
{
node *Q;
while(A->next!=NULL&&A->next->num<x)
A=A->next;
Q=(node*)malloc(sizeof(node));
Q->num=x;
Q->next=A->next;
A->next=Q;
}
Linklist link_node(Linklist pA,Linklist pB)/*合并两个单链表*/
{
Linklist a,b;
Linklist L3;
a=pA->next;
b=pB->next;
node *q;
L3=pA;
while(a->next!=NULL&&b->next!=NULL)
{
if(a->next->num<b->next->num)
{
q=a->next;
a->next=q->next;/*将结点删除*/
q->next=L3->next;
L3->next=q;
L3=L3->next;
}
else if(a->next->num>b->next->num)
{
q=b->next;
b->next=q->next;/*将结点删除*/
q->next=L3->next;
L3->next=q;
L3=L3->next;
}
}
if(a->next!=NULL){
L3->next=a->next;
a->next=NULL;
}
if(b->next!=NULL){
L3->next=b->next;
b->next=NULL;
}
return L3;
}
void print_node(node *E)
{
while(E->next!=NULL)
{
printf("%d ",E->next->num);
E=E->next;
}
}
int main()
{
node *L;
node *L1,*L2;
L1=StartList(L1);
L2=StartList(L2);
int X1,X2;
printf("输入第一个链表元素\n");
for(int L=0;L<3;L++)
{scanf("%d",&X1);
insert_num(L1,X1);
}
print_node(L1);
printf("\n");
printf("输入第二个链表元素\n");
for(int l=0;l<3;l++)
{
scanf("%d",&X2);
insert_num(L2,X2);
}
print_node(L2);
printf("\n");
printf("新链表元素为:\n");
L=link_node(L1,L2);
print_node(L);
}

那就已其中一个链表为基础,将另一个链表的所有节点按序插入就可以了