binaryTreeSerial - juedaiyuer/researchNote GitHub Wiki

#二叉树的序列化和反序列化#

   /*
	* 1. 二叉树的序列化
	* 2. ! 表示一个数值的结束
	* 3. #! 表示一个节点为null
	* 4. 先序遍历法
	*
	* */
	public String serialByPre(TreeNode head){
	    if (head == null){
	        return "#!";
	    }
	    String res = head.value + "!";
	    res += serialByPre(head.left);
	    res += serialByPre(head.right);
	    return res;
	}

##source##

  • 程序员代码面试指南(左程云)-第3章