AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
### 中序遍历-非递归 ![](https://img.kancloud.cn/eb/d6/ebd6a30c9502f2c242488db7c208e7b0_896x722.png) ~~~ // 中序遍历,非递归 public static void in(TreeNode node){ Stack<TreeNode> stack = new Stack<>(); // 头节点入栈 stack.push(node); while(!stack.isEmpty()){ // 左子数入栈 while(node.left != null){ stack.push(node.left); node = node.left; } TreeNode cur = stack.pop(); System.out.print(cur.val+"->"); // 如果有右,则右节点入栈 if(null != cur.right){ stack.push(cur.right); // 将node指针指向右节点 node = cur.right; } } } ~~~ ``` 中序遍历:(非递归) 4->2->5->1->6->3->7-> ```