树与二叉树二叉树的结构123456789101112public class TreeNode{ int val; TreeNode left; TreeNode right; TreeNode(){} TreeNode(int val){this.val = val} TreeNode(int val, TreeNode left, TreeNode right){ this.val=val; this.left = left; this.right = right; }} 二叉树的递归遍历算法先序遍历【递归】1234567891011121314151617class Solution { public List<Integer> preorderTraversal(TreeNode root) { List<Integer> res = new ArrayList<>(); preorder(root, res); return res; } public void preorder(TreeNode root, List<Integer> res) { if (root == null) { return; } res.add(root.val); preorder(root.left, res); preorder(root.right, res); }} 中序遍历【递归】后序遍历【递归】二叉树的非递归遍历算法层次遍历