编写一个算法,打印二叉树上从根到叶子的路径 。(注意,对于打印栈或队列的具体函数,必须自己写出具体算法)
void AllPath(BiTree T , Stack &S){
// 用递归方法进行
if(T)
{
push(S,T->data);
if(!T->lchild && !T->rchild) PrintStack(S);
else
{AllPath(T->lchild,S);
AllPath(T->rchild,S);
}
pop(S);// 左右子树打印完毕,弹出根
}//end if
}//end AllPath
PrintStack(S)
{while(!stackempty(S))
{pop(S,&e);push(S1,e); }
while(!stackempty(S1)
{pop(S1,&e);push(&S2,e); print(e);}
}