赞
踩
满意答案
A2用户
2015.04.24
采纳率:43% 等级:9
已帮助:1315人
#include
#include
struct link{
int data;
struct link *next;
};
struct link *fun(struct link *h1,struct link *h2)
{
struct link *h,*p=NULL;
if(h1 && h2)
h=h1->datadata?h1:h2;
else
{
if(h1)
return h1;
if(h2)
return h2;
return NULL;
}
while(h1 && h2)
{
if(p)
{
if(h1->datadata)
{
p->next=h1;
h1=h1->next;
}
else
{
p->next=h2;
h2=h2->next;
}
p=p->next;
}
else
if(h1->datadata)
{
p=h1;
h1=h1->next;
}
else
{
p=h2;
h2=h2->next;
}
}
p->next=h1?h1:h2;
return h;
}
void main()
{
struct link *h1=NULL,*h2=NULL,*p1,*p2;
int i,a1[10]={1,3,4,5,9,11,15,16,20,25},a2[10]={2,8,10,12,13,19,21,22,23,24};
for(i=0;i<10;i++)
{
if(h1==h2)
{
h1=p1=(struct link *)malloc(sizeof(struct link));
h2=p2=(struct link *)malloc(sizeof(struct link));
}
else
{
p1->next=(struct link *)malloc(sizeof(struct link));
p2->next=(struct link *)malloc(sizeof(struct link));
p1=p1->next;
p2=p2->next;
}
p1->data=a1[i];
p1->next=NULL;
p2->data=a2[i];
p2->next=NULL;
}
h1=fun(h1,h2);
for(p1=h1;p1;p1=p1->next)
printf("%3d",p1->data);
}
00分享举报
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。