题目详情
当前位置:首页 > 计算机考试 > 中级软件设计师
题目详情:
发布时间:2023-11-07 02:09:03

[填空题][说明] 假设二叉树采用连接存储结构进行存储,root 指向根接点,p 所指结点为任一给定的结点,编写一个求从根结点到p所指结点之间路径的函数。
void path (root, p)
btree * root, * p;

Btree *stack[m0], *s;
int tag[m0], top =0, i, find =0;
s =root;
do

while (s ! = NULL)

stack [top] = s;
tag[top] =0;
( (1) )

if (top >0)

( (2) )
if (tag[top] = =1)

if( (3) )

for (i=1; i< =top; i+ + printf ("%d" ,stack[i]- >data);
find=1;

else top - -;

if( (4) )

p=p- >right;
( (5) )


while (find || (s! = NULL && top ! =0));

更多"[说明] 假设二叉树采用连接存储结构进行存储,root 指向根接点,p"的相关试题:

[填空题][说明] 假设二叉树采用连接存储结构进行存储,root 指向根接点,p 所指结点为任一给定的结点,编写一个求从根结点到p所指结点之间路径的函数。 void path (root, p) btree * root, * p; { Btree *stack[m0], *s; int tag[m0], top =0, i, find =0; s =root; do { while (s ! = NULL) { stack [top] = s; tag[top] =0; ( (1) ) } if (top >0) { ( (2) ) if (tag[top] = =1) { if( (3) ) { for (i=1; i< =top; i+ + printf ("%d" ,stack[i]- >data); find=1; } else top - -; } if( (4) ) { p=p- >right; ( (5) ) } } } while (find || (s! = NULL && top ! =0)); }
[填空题] 假设采用动态存储分配的顺序串HString作为串的存储结构。该类型实现的串操作函数原型说明如下:
void strinit(HString s); //置s为空串
int strlen(HString s); //求串s的长度
void strcpy(HString to,HString from); //将串from复制到串to
void streat(HString to,HString from); //将串from联接到串to的末尾
int strcmp(HString s1,HString s2);
//比较串s1和s2的大小,当s1<s2,s1=s2或s1>s2时,
//返回值小于0,等于0或大于0
HString substr(HString s,int i,int m);
//返回串S中从第i(0≤i≤strlen(s)-m)个字符起长度为m的子串阅读下列算法f32,并回答问题:
(1)设串S="abcdabcd",T="bcd",V="bcda",写出执行f32(S,T,V)之后的S;
(2)简述算法f32的功能。
void f 32(HString S,HString T,HString V){
int m,n,pos,i;
HString news;
strinit(news);
n=strlen(S);
m=strlen(T);
pos=i=0;
while(i<=n-m){
if(strcmp(substr(S,i,m),T)!=0)i++;
else{
strcat(news,substr(S,pos,i-pos));
strcat(news,V);
pos=i=i+m;
}
}
strcat(news,substr(S,pos,n&md
[填空题][说明] 假设二叉树采用链式存储方式存储,编写一个后序遍历二叉树的非递归方式。
Void postorder (btree * B)

btree * stack [m0] , *p;
int tag [m0], top =0;
p=b;
do

while (p! =NULL)

top+ +;
(1)
tag [top] =0;
p =p- >left;

if (top >0)

(2)
if (tag[top3 = =1)

(3)
print ("%d", p- >data);

if(top>0)

(4)
tag [top] = 1;


while (p! = NULL && top ! =0)

[填空题][说明] 假设二叉树采用链式存储方式存储,编写一个后序遍历二叉树的非递归方式。 Void postorder (btree * B) { btree * stack [m0] , *p; int tag [m0], top =0; p=b; do { while (p! =NULL) { top+ +; (1) tag [top] =0; p =p- >left; } if (top >0) { (2) if (tag[top3 = =1) { (3) print ("%d", p- >data); } if(top>0) { (4) tag [top] = 1; } } } while (p! = NULL && top ! =0) }
[填空题][说明]
已知一棵二叉树用二叉链表存储,t指向根结点,p指向树中任一结点。下列算法为输出从t到p之间路径上的结点。
[函数]
#define MaxSize 1000
typedef struct node
TelemType data;
struct node *lchild,*rchild;
BiNode, *BiTree;
void Path(BiTree t, BiNode *p)
BiTree *stack EMaxsize], *stack1 [maxsize], *q;
int tag[Maxsizel, top=0, top1;
q=t;
/*通过前序遍历发现P*/
do while (q!=NULL&&q! =p)
/*扫描左孩子,且相应的结点不为p*/
(1) ;
stack [top] =q;
tag [top] =0;
(2) ;

if (top>0)
if (stack [top]==P) break; /*找到p,栈底到栈顶为t到p*/
if(tag[top]==1) top--;
else q=stack[top];
q=q->rchild;
tag [top] =1;


(3) ;
top--; top1=0;
while(top>0)
q=stack [top]; /*反向打印准备*/
top1++;
(4) ;
top--;

while( (5) ) /*打印栈的内容*/
q=stack1[top1];
printf (q->data);
top1--;



[填空题][说明]
已知一棵二叉树用二叉链表存储,t指向根节点,P指向树中任一节点。下列算法为输出从t到P之问路径上的节点。
[C程序]
#define MaxSize 1000
typedef struct node
TelemType data ;
struct node *ichiid,*rchiid;
BiNode,*BiTree;
void Path(BiTree t,BiNode *P)
BiTree *stack[Maxsize],*stackl[Maxsize],*q;
int tag[Maxsize],top=0,topl;
q=t;
/*通过先序遍历发现P*/
dowhile(q!=NULL &&q!=p)
/*扫描左孩子,_日.相应的节点不为P*/
(1)
stack[top]=q;
tag[top]=0;
(2)

if(top>0)
if(stack[top]=P) break; /*找到P,栈底到栈顶为t到P*/
if(tag[top]==1)top--;
else q=stack[top];
q=q->rchiid;
tag[top]=1;


(3)
top--;topl=0;
while(top>0)
q=stack[top]; /*反向打印准备*/
topl++;
(4)
top--;

while( (5) ) /*打印栈的内容*/
q=stackl[topl]j
printf(q->data);
topl--;


[简答题]假设线性表采用顺序存储结构,其类型定义如下: #define ListSize 100 typedef struct{ int data[ListSize]; int length; }SeqList,*Table; 编写算法,将顺序表L中所有值为奇数的元素调整到表的前端。
[填空题]已知具有n个元素的一维数组采用顺序存储结构,假设每个元素占k个存储单元,若第一个元素的地址为LOC(a1),那么第1今元素地址LOC(ai)= ______。
[多项选择]假设二叉树采用二叉链表存储结构存储,试设计一个算法,求出该二叉树中第一条最长的路径长度以及此路径上个结点的值。
[填空题]若长度为n的线性表采用顺序存储结构,在等概率假设的情况下,删除一个数据元素,需要先依次移动 【1】 个数据元素。
[填空题]若长度为n的线性表采用顺序存储结构,在等概率假设的情况下,删除一个的数据元素,需要先依次移动 ______个数据元素。

我来回答:

购买搜题卡查看答案
[会员特权] 开通VIP, 查看 全部题目答案
[会员特权] 享免全部广告特权
推荐91天
¥36.8
¥80元
31天
¥20.8
¥40元
365天
¥88.8
¥188元
请选择支付方式
  • 微信支付
  • 支付宝支付
点击支付即表示同意并接受了《购买须知》
立即支付 系统将自动为您注册账号
请使用微信扫码支付

订单号:

请不要关闭本页面,支付完成后请点击【支付完成】按钮
恭喜您,购买搜题卡成功
重要提示:请拍照或截图保存账号密码!
我要搜题网官网:https://www.woyaosouti.com
我已记住账号密码