二叉树打印
来源:互联网 发布:维基百科数据库下载 编辑:程序博客网 时间:2024/05/22 17:48
import java.util.ArrayList;
public class tmp1 {
public static void main(String[] args) {
TreeNode p1 =null;
}
public static int count = 0;
public static ArrayList<ArrayList<Integer>> row = new ArrayList<ArrayList<Integer>>();
public static ArrayList<ArrayList<Integer>> Print(TreeNode pRoot) {
if (pRoot == null)
return row;
else {
depth(pRoot);
return row;
}
}
public static void depth(TreeNode pRoot) {
count++;
if (count > row.size()) {
ArrayList<Integer> al = new ArrayList<>();
row.add(al);
}
row.get(count - 1).add(pRoot.val);
if (pRoot.left != null)
depth(pRoot.left);
if (pRoot.right != null)
depth(pRoot.right);
count--;
}
public static class TreeNode {
int val = 0;
TreeNode left = null;
TreeNode right = null;
public TreeNode(int val) {
this.val = val;
}
}
}
public class tmp1 {
public static void main(String[] args) {
TreeNode p1 =null;
}
public static int count = 0;
public static ArrayList<ArrayList<Integer>> row = new ArrayList<ArrayList<Integer>>();
public static ArrayList<ArrayList<Integer>> Print(TreeNode pRoot) {
if (pRoot == null)
return row;
else {
depth(pRoot);
return row;
}
}
public static void depth(TreeNode pRoot) {
count++;
if (count > row.size()) {
ArrayList<Integer> al = new ArrayList<>();
row.add(al);
}
row.get(count - 1).add(pRoot.val);
if (pRoot.left != null)
depth(pRoot.left);
if (pRoot.right != null)
depth(pRoot.right);
count--;
}
public static class TreeNode {
int val = 0;
TreeNode left = null;
TreeNode right = null;
public TreeNode(int val) {
this.val = val;
}
}
}
0 0
- 【二叉树】二叉树打印
- 分层打印二叉树
- ZigZag打印二叉树
- 分层打印二叉树
- 横向打印二叉树
- 用凹入表打印二叉树
- 完美打印二叉树
- 逐行打印二叉树
- 之字形打印二叉树
- 层次打印二叉树
- 之字形打印二叉树
- 打印二叉树
- 层次打印二叉树
- 二叉树打印
- 二叉树打印
- 从上到下打印二叉树
- 二叉树打印成多行
- 二叉树打印
- Android SQLiteOpenHelper 实例方法getReadableDatabase()和getWritableDatabase() 区别
- 2017华为笔试、面试经历
- Idea的mybatis插件破解
- Semi-prime H-numbers(素数筛)
- JAVA基础--ArrayList
- 二叉树打印
- 第三周项目3 顺序表的应用
- 计算面积
- X-factor Chains(素数)
- Prime Path(素数筛+BFS)
- js——小动画
- Wall_poj1113_凸包
- 数据库管理工具——SQuirreL SQL Client使用入门
- Dead Fraction(辗转相除法)