6.41
来源:互联网 发布:2k16mc科比捏脸数据 编辑:程序博客网 时间:2024/06/18 10:39
6.41③ 编写递归算法,在二叉树中求位于先序序列中
第k个位置的结点的值。
要求实现下列函数:
TElemType PreOrder(BiTree bt, int k);
/* bt is the root node of a binary linked list, */
/* Preorder travel it and find the node whose */
/* position number is k, and return its value. */
/* if can't found it, then return '#'. */
二叉链表类型定义:
typedef struct BiTNode {
TElemType data;
BiTNode *lchild, *rchild;
if(!bt)return '#';
TElemType e;
if(i==k)return bt->data;
i++;
e=PreCount(bt->lchild,k,i);
if(e=='#')
return PreCount(bt->rchild,k,i);
else return e;
}
TElemType PreOrder(BiTree bt, int k)
/* bt is the root node of a binary linked list, */
/* Preorder travel it and find the node whose */
/* position number is k, and return its value. */
/* if can't found it, then return '#'. */
{
int i=1;
return PreCount(bt,k,i);
}
第k个位置的结点的值。
要求实现下列函数:
TElemType PreOrder(BiTree bt, int k);
/* bt is the root node of a binary linked list, */
/* Preorder travel it and find the node whose */
/* position number is k, and return its value. */
/* if can't found it, then return '#'. */
二叉链表类型定义:
typedef struct BiTNode {
TElemType data;
BiTNode *lchild, *rchild;
} BiTNode, *BiTree;
************************************************************************************************************
TElemType PreCount(BiTree bt,int k,int &i)
{if(!bt)return '#';
TElemType e;
if(i==k)return bt->data;
i++;
e=PreCount(bt->lchild,k,i);
if(e=='#')
return PreCount(bt->rchild,k,i);
else return e;
}
TElemType PreOrder(BiTree bt, int k)
/* bt is the root node of a binary linked list, */
/* Preorder travel it and find the node whose */
/* position number is k, and return its value. */
/* if can't found it, then return '#'. */
{
int i=1;
return PreCount(bt,k,i);
}
- 6.41
- csapp2e 家庭作业 6.41
- 严蔚敏 数据结构习题 6.41
- JAVA基础6.41——JAVA文档注释
- @protocol 协议名 <其它协议,。。>
- mips 异常处理和进程切换
- (文件下载)Can not find a java.io.InputStream with the name [inputStream] in the invocation stack
- 国嵌视频学习第四天-进程通信
- iphone 开发 官方 第一例
- 6.41
- 数学建模浅谈
- C#多线程学习(二) 如何操纵一个线程
- 近似证明哥德巴赫猜想
- qemu kvm 内存虚拟化
- C#多线程学习(三) 生产者和消费者
- /*关闭所有的LED指示灯*/ /*点亮所有的灯*/
- 剖析Struts1中的五个对象(一)
- word打开慢的解决办法