c语言编写无序顺序表,请用c语言写 在非递减有序的顺序表中插入一个元素x,保持顺序表有序性...

满意答案

00e27ab806e4881f8254fe7ae8741834.png

A2用户

2015.04.24

00e27ab806e4881f8254fe7ae8741834.png

采纳率: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分享举报

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值