运行没有输出,请大家帮我看看
题目:设链表 A=(a1,a2,…,am),B=(b1,b2,…,bn),试编写一个按下列规则合并 A、B 为链表 C 的算法,使得: (利用原表结点空间)。
C=(a1,b1,…,am, bm, bm+1,…bn) m≤n
C=(b1,a1,…,bn, an, an+1,…am) m
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int date;
struct node* next;
}node,*list;
list create(int*len);
int main()
{
int m,n;
list A=create(&m);
list B=create(&n);
list C;
list p=A->next,q=B->next;
if(m<=n){
C=A;
while(p&&q){
list t=p->next;
list s=q->next;
q->next=p->next;
p->next=q;
p=t;
q=s;
}
p->next=q;
free(B);
}
else if(m>n){
while(p&&q){
C=B;
list t=q->next;
list s=p->next;
p->next=q->next;
q->next=p;
q=t;
p=s;
}
q->next=p;
free(A);
}
list f=C->next;
while(f){
printf("%d ",f->date);
}
return 0;
}
list create(int*len)
{
int x,i=0;
list head=(list)malloc(sizeof(node));
head->date=0;
head->next=NULL;
list q=head;
do{
scanf("%d",&x);
i++;
list p=(list)malloc(sizeof(node));
p->date=x;
q->next=p;
p->next=NULL;
q=p;
}while(getchar()!='\n');
return head;
}
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int date;
struct node *next;
} node, *list;
list create(int *len);
list insert(list P, list Q) // Q插入到P,保留P
{
list p, q, t, s;
p = P->next, q = Q->next;
while (p->next)
{
t = p->next;
s = q->next;
p->next = q;
q->next = t;
p = t;
q = s;
}
if (q)
p->next = q;
free(Q);
return P;
}
int main()
{
int m, n;
list A = create(&m);
list B = create(&n);
list C;
if (m <= n)
C = insert(A, B);
else
C = insert(B, A);
list f = C->next;
while (f)
{
printf("%d ", f->date);
f = f->next;
}
return 0;
}
list create(int *len)
{
int x;//, i = 0;
*len=0;
list head = (list)malloc(sizeof(node));
head->date = 0;
head->next = NULL;
list q = head;
do
{
scanf("%d", &x);
(*len)++;//i++;
list p = (list)malloc(sizeof(node));
p->date = x;
q->next = p;
p->next = NULL;
q = p;
} while (getchar() != '\n');
return head;
}