#include <stdio.h>
#include <stdlib.h>
typedef struct node{
int data;
struct node *next;
}node, *linklist;
linklist creat( )
{
node *p, *q, *f;
linklist head;
int e;
head = (node *)malloc(sizeof(node));
head ->next = NULL;
do{
f = (node *)malloc(sizeof(node));
scanf("%d", &e);
f -> data = e;
q = head; p = head -> next;
while(p && e > p -> data){
q =p; p = p-> next;
}
f -> next = p; q -> next =f;
}while(e - 9);
return head;
}
void hua_output(linklist L)
{
node *p;
p = L -> next;
printf("/n表中各节点为:");
while(p != 0){
printf("/t%d", p -> data);
p = p -> next;
}
printf("/n");
}
linklist merge(linklist A,linklist B)
{
node *p, *q, *s, *C;
p = A ->next; q = B ->next;
s = (node *)malloc(sizeof(node));
C = s;
s ->next = NULL;
free(B);
while(p&&q){
if(p ->data < q ->data){
C->next = p;
C = p;
p = p->next;
}
else{
C->next = q ;
C = q;
q = q ->next;
}
}
if(p == NULL)
p = q;
while(p){
C->next = p ;
C = p;
p = p ->next;
}
return s;
}
/*linklist hua_link( )
{
linklist L;
node *p;
int x;
do{
p = (node *)malloc(sizeof(node));
scanf("%d", &x);
p -> data = x;
p = p -> next;
}while(x - 9);
L = p;
return L;
}
void hua_sequ( linklist L )
{
linklist H, S;
H = (node *)malloc(sizeof(node));
node *q, *p;
q = L;
p = L;
// p = p ->next;
do{
if((q ->data) > (p ->data)){
H ->data = p ->data;
H = H ->next;
H ->data = q ->data;
}
else{
H ->data = q ->data;
H = H->next;
H ->data = p ->data;
}
p = p ->next;
q = q ->next;
}while(p);
S = H;
while(S != 0){
printf("/t%d", S -> data);
S = S -> next;
}
}*/
void main ( )
{
linklist L1,L2, L3;
printf("<1>输入数列,(输入9则结束):/n");
L1 = creat( );
hua_output(L1);
printf("/n<2>再输入数列,(输入9则结束):/n");
L2 = creat( );
hua_output(L2);
printf("/n<3>两单链表合并后:");
L3 = merge(L1, L2);
hua_output(L3);
}