import java.util.*;
/*
* public class TreeNode {
* int val = 0;
* TreeNode left = null;
* TreeNode right = null;
* }
*/
public class Solution {
/**
*
* @param root TreeNode类 the root of binary tree
* @return int整型二维数组
*/
public int[][] threeOrders (TreeNode root) {
List<Integer> prelist = new ArrayList<>();
Pre(root,prelist);
List<Integer> inlist = new ArrayList<>();
in(root,inlist);
List<Integer> postlist = new ArrayList<>();
post(root,postlist);
int[][] res = { //将ArrayList转化为int数组
prelist.stream().mapToInt(Integer::valueOf).toArray(),
inlist.stream().mapToInt(Integer::valueOf).toArray(),
postlist.stream().mapToInt(Integer::valueOf).toArray()
};
return res;
}
public void Pre(TreeNode root, List<Integer> list){
if(root != null){
list.add(root.val);
Pre(root.left,list);
Pre(root.right,list);
}
}
public void in(TreeNode root, List<Integer> list){
if(root != null){
in(root.left,list);
list.add(root.val);
in(root.right,list);
}
}
public void post(TreeNode root, List<Integer> list){
if(root != null){
post(root.left,list);
post(root.right,list);
list.add(root.val);
}
}
}