二叉树叶子节点路径的遍历
1.输出所有叶子节点的路径(特殊情况输出指定叶子节点的路径)
viod AllPath(Btree* t,stack* s) { if(t) { s.push(t); if(!t->lchild&&t->rchild) print(s); else
{
AllPath(t->lchild,s);
AllPath(t->rchild,s);
}
s.pop(); } }
树的叶子节点的路径遍历算法
path(Btree* t,stack*s) { while(t) { s.push(t) if(!t->lchild) print(s); else path(p->lchild,s); s.pop(s); t=t->rchild; } }
浙公网安备 33010602011771号