//队列和栈
void InvertLevel(BiTree bt)
{
Stack s;
Queue Q;
if (bt != NULL)
{
InitStack(s);
InitQueue(Q);
EnQueue(Q, bt);
while (!IsEmpty(Q))
{
DeQueue(Q, p);
push(s, p);
if (p->lchild)
EnQueue(Q, p->lchild);
if (p->rchild)
EnQueue(Q, p->rchild);
}
while (!IsEmpty(s))
{
pop(s, p);
visit(p->data);
}
}
}
自下而上,自右至左的层次遍历
最新推荐文章于 2025-04-28 16:56:44 发布