如何用非递规来做二叉树的后序遍历

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;  
     }  
}  
}  
}  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值