如何用非递规来做二叉树的后序遍历
来源:互联网 发布:粒子群算法参数 编辑:程序博客网 时间:2024/05/01 10:02
Q :如何用非递规来做二叉树的后序遍历主要解答者:zgy231552提交人:langhaixin感谢:zgy231552审核者:starfish社区对应贴子:查看 A :
二叉树的结构
struct bt
{
char data;
struct bt *ltree;
struct bt *rtree;
}
---------------------------------------------------------------
上次写错了struct bt
//要设置一个标志位tag
{
char data;
int tag;
struct bt *ltree;
struct bt *rtree;
}
typedef struct bt BT;
typedef BT *link;
link root=NULL;
link create_tree(link root)
{..................};
void postorder(link root)
{
link p=root;
while(p!=NULL&&!isempty())
{
while(p!=NULL)
{ //push it into the stack
p->tag=0;//left tree
top++;
push(stack,p);
p=p->left;
}
int continue=1;
while(p!=NULL&&continue)
{
p=gettop(stack);
pop();
switch(p->tag){
case 0: continue=0;
p->tag=1;
push(stack,p);
p=p->right;
break;
case 1: printf("%c",p->data);
break;
}
}
}
}
二叉树的结构
struct bt
{
char data;
struct bt *ltree;
struct bt *rtree;
}
---------------------------------------------------------------
上次写错了struct bt
//要设置一个标志位tag
{
char data;
int tag;
struct bt *ltree;
struct bt *rtree;
}
typedef struct bt BT;
typedef BT *link;
link root=NULL;
link create_tree(link root)
{..................};
void postorder(link root)
{
link p=root;
while(p!=NULL&&!isempty())
{
while(p!=NULL)
{ //push it into the stack
p->tag=0;//left tree
top++;
push(stack,p);
p=p->left;
}
int continue=1;
while(p!=NULL&&continue)
{
p=gettop(stack);
pop();
switch(p->tag){
case 0: continue=0;
p->tag=1;
push(stack,p);
p=p->right;
break;
case 1: printf("%c",p->data);
break;
}
}
}
}
- 如何用非递规来做二叉树的后序遍历
- 如何用一个栈实现二叉树的螺旋遍历
- 如何用堆栈实现后序遍历的非递归程序
- 二叉树的后序遍历
- 二叉搜索树的后序遍历
- 二叉搜索树的后序遍历
- 二叉树的后序遍历
- 二叉搜索树的后序遍历
- 二叉树的后序遍历算法
- 题目:二叉树的后序遍历
- LintCode -- 二叉树的后序遍历
- Lintcode 二叉树的后序遍历
- 二叉搜索树的后序遍历
- LintCode:二叉树的后序遍历
- 二叉树的后序遍历
- 二叉查找树的后序遍历
- 二叉搜索树的后序遍历
- lintcode,二叉树的后序遍历
- 如何在Windows Server 2003中启用了Active Directory的情况下将 DNS 与现有 DNS 结构集成
- 用存储过程生成单据号
- 今天,你O/R Mapping了吗?
- 用二叉树的中序和前序还原二叉树
- 编写一个判断二叉树是否为完全二叉树的C语言函数
- 如何用非递规来做二叉树的后序遍历
- 简单Huffman编码
- 程序员 做军官还是做特种兵?
- 有关串口的一个调试错误,真是狂昏!!!
- “多态性”是C++最关键和核心的一个特性,“动态绑定技术”是C++编译器最重要的一个技术!欢迎C++高手进来指正我的粗浅理解
- AI+SVG的继续学习
- 请教:BCB与Matlab的联接问题
- So what are inner classes good for anyway?(翻译 by Gee)
- 两个新玩意