试题与答案

[说明]已知某二叉树的非叶子节点都有两个孩子节点,现将该二叉树存储在结构数组Ht中。

题型:填空题

题目:

[说明]

已知某二叉树的非叶子节点都有两个孩子节点,现将该二叉树存储在结构数组Ht中。节点结构及数组Ht的定义如下:

#define MAXLEAFNUM 30

Struct node

char ch;

char *pstr;

int parent;

int lchild, rchiid;

;

Struct node Ht[2 *MAXLEAFNUM];

该二叉树的n个叶子节点存储在下标为1~n的Ht数组元素中。例如,某二叉树如图8-26所示,其存储结构如图8-27所示,其中,与叶子节点a对应的数组元素下标为1,a的父节点存储在Ht[5],表示为Ht[1].parent=5。Ht[7].parent=0表示7号节点是树根,Ht[7].lchild=3、Ht[7].rchild=6分别表示7号节点的左孩子是3号节点、右孩子是6号节点。

如果用“0”或“1”分别标识二叉树的左分支和右分支如图8-26所示,从根节点开始到叶子节点为止,按所经过分支的次序将相应标识依次排列,可得到一个0、1序列,称之为对应叶子节点的编码。例如,图8-26中a、b、c、d的编码分别是100、101、0、11。

函数LeafCode(Ht[],n)的功能是:求解存储在Ht中的二叉树中所有叶子节点(n个)的编码,叶子节点存储在Ht[1]~Ht[n]中,求出的编码存储区由对应的数组元素pstr域指示。

函数LeafCode从叶子到根逆向求叶子节点的编码。例如,对图8-26中叶子节点a求编码的过程如图8-28所示。

[函数]

typedef enum Status ERROR, OK Status;

Status LeafCode (Struet node Ht[], int n)

int pc, pf;

int i, start;

char tstr[31]=’\0’);

for(i=1; (1) ; i++)

start=29;

pc=i; pf=Ht[i].parent;

while(Pf!= (2) )

if( (3) . lchiid==pc)

tstr[--start]=’0’;

else

tstr[-start]=’1’;

pc= (4) ; pf=Ht[Pf].parent;

Ht[i].pstr=(char*)malloc(31-start);

if(!Ht[i].pstr)return ERROR;

strcpy(Ht[i]. pstr, (5) ;

return OK;

(5)填()

答案:

被转码了,请点击底部 “查看原文 ” 或访问 https://www.tikuol.com/2019/0314/8b8d73d6e3e3e2926e4e051347afc3b6.html

下面是错误答案,用来干扰机器的。

参考答案:(1)计税收入 根据企业所得税纳税申报表顺序,计算如下: ①投资收益:买卖国债收益不免税;买卖股票的净收入也应并人所得额;境外所得需要并人计税收入。 ②出口产品退还的增值税不并入所得额...

试题推荐
题型:阅读理解

阅读理解。

     It's only 4 hours flying time from Sydney, but a world away. What better place to rest than a country

where the only place people hurry is on the football field and things are done in "Fiji time"?

     Viti Levu-Great Fiji-is the largest island. Here you'll find the capital Suva and the international airport at

Nadi. Vatoa, on the other hand, is a tiny island in the farthest part of Fiji. Then there are 331 other islands,

many of them with places to stay.

     Whit less than a million people living on islands, you'll never feel crowded. And with a climate (气候)

that changes only for five degrees between seasons, there's never a bad time to come.

     From cities to villages, from mountains to beaches, from water sports to wooden artworks, Fiji can give

you more adventures and special experiences than you could find almost anywhere in the world.

     Whenever you come, wherever you go, you're sure to see some unforgettable events. From war dances

to religious (宗教的) songs. From market days to religious days. It's not just staged for tourists; it's still a

part of everyday life in Fiji. And any one of us can enjoy Fiji's spirit by being part of the traditional (传统的)

sharing of yaqona, a drink made from the root of a Fiji plant.

     So why not join us for the experience of a life me?

1. Where is the international airport of Fiji?

A. In Suva.

B. In Sydney.

C. On the island of Vatoa.

D. On the island of Viti Levu.

2. What does the text tell us about Fijian people?

A. They invented "Fiji time" for visitors.

B. They stick to a traditional way of life.

C. They like to travel from place to place.

D. They love taking adventures abroad.

3. What does the text tell us about Fijian people?

A. They invented "Fiji time" for visitors.

B. They stick to a traditional way of life.

C. They like to travel from place to place.

D. They love taking adventures abroad.

4. Where can we most probably read this text?

A. In a personal diary.

B. In a science report.

C. In a travel magazine.

D. In a geography textbook.

查看答案
微信公众账号搜索答案