
二叉树
文章平均质量分 69
也非野人
这个作者很懒,什么都没留下…
展开
-
二叉树的序列化
首先我们介绍二叉树先序序列化的方式,假设序列化的结果字符串为str,初始时str等于空字符串。先序遍历二叉树,如果遇到空节点,就在str的末尾加上“#!”,“#”表示这个节点为空,节点值不存在,当然你也可以用其他的特殊字符,“!”表示一个值的结束。如果遇到不为空的节点,假设节点值为3,就在str的末尾加上“3!”。现在请你实现树的先序序列化。 给定树的根结点root,请返回二叉树序列化后的字原创 2016-06-24 15:46:58 · 371 阅读 · 0 评论 -
二叉树的递归实现(先,中,后)
package erchashu; import java.util.ArrayList; import java.util.List; public class diguierchashu { public static List list1 =new ArrayList(); public static List list2 =new ArrayList(); pu原创 2016-06-23 15:15:57 · 307 阅读 · 0 评论 -
二叉树的非递归实现(先,中,后)
先序 public void xianxu(TreeNode root) { if(root == null) return ; stack.push(root); while(!stack.isEmpty()){ TreeNode tmp =stack.pop(); System.out.print(tmp.val+" ");原创 2016-06-23 15:18:25 · 302 阅读 · 0 评论