上海龙凤1314 shlf

后序遍历非递归算法

时间:2018-12-31 12:00:00 资料大全 我要投稿

后序遍历非递归算法

后序遍历非递归算法

#define maxsize 100
typedef enum{L,R} tagtype;
typedef struct
{
    Bitree ptr;
    tagtype tag;
}stacknode;

typedef struct
{
    stacknode Elem[maxsize];
    int top;
}SqStack;


//后序遍历
void PostOrderUnrec(Bitree t)
{
    SqStack s;
    stacknode x;
    StackInit(s);
    p=t;
  
    do
    {
        while (p!=null)       //遍历左子树
        {
            x.ptr = p;
            x.tag = L;        //标记为左子树
            push(s,x);
            p=p->lchild;
        }
   
        while (!StackEmpty(s) &&s.Elem[s.top].tag==R) 
        {
            x = pop(s);
            p = x.ptr;
            visite(p->data);   //tag为R,表示右子树访问完毕,故访问根结点      
        }
       
        if (!StackEmpty(s))
        {
            s.Elem[s.top].tag =R;    //遍历右子树
           p=s.Elem[s.top].ptr->rchild;       
        }   
    }while (!StackEmpty(s));
上海龙凤1314 shlf }//PostOrderUnrec

 

【后序遍历非递归算法】相关文章:

1.先序遍历非递归算法

2.中序遍历非递归算法笔试题

3.层次遍历算法笔试题

4.递归实现回文判断

5.程序员递归面试问题及解析

6.笔试题(算法类)

7.迅雷笔试 算法 智力 上机

8.迅雷算法类笔试真题