void level_reverse(TNode* p)
{
Queue Q;
Stack S;
InitQueue(Q);
InitStack(S);
if(p!=NULL)
{
EnQueue(Q,p);
while(!QueueEmpty(Q))
{
DeQueue(Q,p);//操作队头
Push(S,p);
if(p->lchild!=NULL)
EnQueue(Q,p->lchild);
if(p->rchild!=NULL)
EnQueue(Q,p->rchild);
}
}
while(StackEmpty(S)!=true)
{
Pop(S,p);
visit(p);
}
}
王道课后习题4.3.4:二叉树的自下而上,从右到左的层次遍历算法
最新推荐文章于 2024-01-02 18:15:01 发布