- public static void midOrderNonRec1(TreeNode root, Visitor visitor) {
- if(root == null) return;
- Stack<TreeNode> s = new Stack<TreeNode>();
- TreeNode p = root;
- while( p != null || !s.empty() ) {
- while( p != null ) {
- s.push(p);
- p = p.left;
- }
- if(!s.empty()) {
- p = s.pop();
- visitor.visit(p);
- p = p.right;
- }
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/1105201512540.html
来源: http://www.codesnippet.cn/detail/1105201512540.html