#include<stdio.h>
#include<stdlib.h>
typedef struct number NUM;
struct number
{
int num;
NUM *next;
};
int main()
{
int m,n,i;
NUM *head1,*head2,*p,*q,*tp,*tq;
head1=(NUM *)malloc(sizeof(NUM));
head2=(NUM *)malloc(sizeof(NUM));
p=head1;
scanf("%d",&m);
for(i=0;i<m;i++)
{
p->next=(NUM *)malloc(sizeof(NUM));
p=p->next;
scanf("%d",&p->num);
p->next=NULL;
}
q=head2;
scanf("%d",&n);
for(i=0;i<n;i++)
{
q->next=(NUM *)malloc(sizeof(NUM));
q=q->next;
scanf("%d",&q->num);
q->next=NULL;
}
tp=head1;
tq=head2;
p=tp->next;
q=tq->next;
while(p && q)
{
if(p->num <= q->num)
{
tp=p;
p=p->next;
}
else
{
tp->next=q;
tp=q;
tq->next=q->next;
q->next=p;
q=tq->next;
}
}
p=head1->next;
q=head2->next;
while(p)
{
printf("%d ",p->num);
p=p->next;
}
while(q)
{
printf("%d ",q->num);
q=q->next;
}
printf("\n");
return 0;
}
[ New Thread ]
Problem 3978 >> 答案错误50% |
201803140220 @ 2019-05-29 20:40:10
|