数据结构单链表(填空题)

#include“stdio.h”#include“alloc.h”structnode{chardata;structnode*next;}listnode;typed... #include “stdio.h”

#include “alloc.h”

struct node

{

char data;

struct node *next;

} listnode;

typedef struct node *link;

void print(link head)

{

struct node *p;

printf(“\n”);

printf(“\n”);

p= head->next;

while(p)

{printf(“%c”, p->data);____(1)____ ;}

}

link creat() /*头插法建立单链表*/

{

link head ,s;

char ch;

head = malloc(sizeof(listnode));

head->next =NULL;

while(( ch= getchar())!=’\n’)

{

s= malloc(sizeof(listnode));

s->data= ch;

s->next =_____(2)_____ ;

_______(3)_______ = s;

}

return head;

}

link merge(link a , link b)

{

link p , q , s , c;

c= malloc(sizeof(listnode));

c->next =NULL;

p=a;

q=b;

while(p->next&&q->next)

{

if (p->next->data<q->next->data)

{ s = p->next;p->next=s->next;}

else

{ s = q->next;q->next = s->next;}

s->next = c->next;

c->next = s;

}

while (p->next)

{

s = p->next;

p->next = s->next;

s->next = c->next;

c->next = s;

}

while(q->next)

{

s = q->next;

q->next = s->next;

s->next = c->next;

c->next = s;

}

free(p);free(q);

return c;

}

main()

{

link a , b , c;

a = creat();

b = creat();

print(a);

print(b);

c = merge ( _______(4)_____ );

print(c);

printf(“\n”);

}

输入:ysplhd

zyxrmhb

输出 ______(5)_______

__________(6)______

__________(7)_____
展开
 我来答
lizard1861
2010-04-04 · TA获得超过800个赞
知道小有建树答主
回答量:543
采纳率:0%
帮助的人:683万
展开全部
#include "stdio.h"
#include "malloc.h"
struct node
{
char data;
struct node *next;
}listnode;
typedef struct node *link;
void print(link head)
{
struct node *p;
printf("\n");
p= head->next;
while(p)
{printf("%c",p->data);p=p->next;}
}

link creat() /*头插法建立单链表*/
{
link head ,s;
char ch;
head =(link)malloc(sizeof(listnode));
head->next =NULL;
while(( ch= getchar())!='\n')
{
s= (link)malloc(sizeof(listnode));
s->data= ch;
s->next =head->next;
head->next = s;
}
return head;
}

link merge(link a , link b)
{
link p, q, s, c;
c=(link) malloc(sizeof(listnode));
c->next =NULL;
p=a;
q=b;
while(p->next&&q->next)
{
if (p->next->data<q->next->data)
{ s = p->next;p->next=s->next;}
else
{ s = q->next;q->next = s->next;}
s->next = c->next;
c->next = s;
}
while (p->next)
{
s = p->next;
p->next = s->next;
s->next = c->next;
c->next = s;
}
while(q->next)
{
s = q->next;
q->next = s->next;
s->next = c->next;
c->next = s;
}

free(p);free(q);
return c;
}
void main()
{
link a, b, c;
a = creat();
b = creat();
print(a);
print(b);
c = merge (a,b);
print(c);
printf("\n");
}

/*
输入:ysplhd

zyxrmhb

输出: dhlpsy
bhmrxyz
zyyxsrpmlhhdb
*/
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
石水2
2010-04-04 · TA获得超过2173个赞
知道小有建树答主
回答量:940
采纳率:100%
帮助的人:920万
展开全部
1.p=p->next;
2.s->next=head->next;
3.head->next=s;
4.c=merge(a,b);

如果想要编译运行的话,要把中文状态下的符号全部转换为英文状态下的.
......
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式