#include
#include
typedef struct List{
int num ;
struct List * next ;
} L ;
void buildLink(struct List * head)
{
L *p, *q ;
q = head;
int i;
for ( i = 1; i <= 5 ; i++)
{
p=(L *)malloc(sizeof(L));
p->num = i;
q->next=p;
q = p;
}
p->next = NULL;
}
void main()
{
L *p , *q , *r, *head1, *head2 ; // *temp;
// L *head3, *r ,*s ;
q=head1=(L *)malloc(sizeof(L));
int i;
for (i=1 ; i<=4 ; i++)
{
p = (L *)malloc(sizeof(L));
printf("Input number %d please:",i);
scanf("%d",&p->num);
q ->next = p ;
q = p ;
}
p->next = NULL ;
head2 = (L *)malloc(sizeof(L));
buildLink(head2);
p = head2->next ;
while(p!=NULL)
{
printf("%d\n",p->num);
p = p->next ;
}
r = head1;
p = head1->next ;
q = head2->next ;
while (p!=NULL && q!=NULL)
{
if (p->num >= q->num)
{
r->next = q;
r = q;
q = q->next;
}
else
{
r->next = p;
r = p;
p = p->next;
}
}
if(p == NULL)
r->next = q;
if(q == NULL)
r->next= p;
// printf("The third list is :\n");
printf("The new list is :\n");
p= head1->next ;
while(p!=NULL)
{
printf("%d\n",p->num);
p = p->next ;
}
}
能否都贴出来看看啊?