level 6
采用两个栈进行存储,一个是临时栈一个是输出栈,首先根节点压入临时栈,然后开始循环。当临时栈不为空,弹出栈顶节点,按顺序将该节点左右孩子(若不为空)压入临时栈,该节点压入输出栈。该层循环结束后,弹出输出栈内所有节点数据。
2011年11月03日 16点11分
2
level 6
伪代码如下stack<node*> output;stack<node*> temp;node *current = null;temp.push(root);while(!temp.isempty()){ current=temp.pop(); output.push(current); if current.left != null temp.push(current.left); if current.right != null temp.push(current.right);}while (!output.isempty)( current=output.pop(); cout<<current.data<<endl;)
2011年11月03日 16点11分
3