For a binary tree, preorder traversal may be enough.

For example,

    _30_
   /   \   
  10    20
 /     /  \
50    45  35

The result is

30 10 50 # # # 20 45 # # 35 # #
Using a queue to deserialize it . 

But a for multi-way tree, we could also use an array to serialize it, e.g.,

30 10 20 50 45 35

-1   0    0   1    2   2

Serialize a Binary Tree or a General Tree的更多相关文章

  1. What is the difference between a binary tree, a binary search tree, a B tree and a B+ tree?

    Binary Tree : It is a tree data structure in which each node has at most two children. As such there ...

  2. 102. Binary Tree Level Order Traversal (Tree, Queue; BFS)

    Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...

  3. 199. Binary Tree Right Side View (Tree, Stack)

    Given a binary tree, imagine yourself standing on the right side of it, return the values of the nod ...

  4. 124. Binary Tree Maximum Path Sum (Tree; DFS)

    Given a binary tree, find the maximum path sum. For this problem, a path is defined as any sequence ...

  5. 145. Binary Tree Postorder Traversal (Stack, Tree)

    Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary ...

  6. LeetCode -- 1038. Binary Search Tree to Greater Sum Tree

    /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode ...

  7. 【leetcode】1038. Binary Search Tree to Greater Sum Tree

    题目如下: Given the root of a binary search tree with distinct values, modify it so that every node has ...

  8. 【LeetCode】 99. Recover Binary Search Tree [Hard] [Morris Traversal] [Tree]

    Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...

  9. Data Structure Binary Tree: Convert a given tree to its Sum Tree

    http://www.geeksforgeeks.org/convert-a-given-tree-to-sum-tree/ #include <iostream> #include &l ...

随机推荐

  1. 内核printk打印等级

    为了确认内核打印等级以及prink 参数对打印的分级,在led驱动初始化代码[以及exit出口]加入如下代码. 每次insmod .rmmod led模块时,根据打印等级的设置,得到不同的打印结果: ...

  2. 利用 操作符特性 代替if判断语句

    参考:http://blog.csdn.net/speedme/article/details/22916181 1.&&的判断特性 #include <stdio.h> ...

  3. Oracle修改字段长度以及计算天数

    sql修改字段长度的语法: alter table 表名 modify 字段名 字段类型; sql修改字段长度的示例代码 alter table qtline modify qtl_bidernote ...

  4. CentOS6.5下VNC Server远程桌面配置详解

    参考文献: (总结)CentOS Linux下VNC Server远程桌面配置详解 远程桌面连接工具VNC——license Key 我的下载地址为 太平洋下载 VNC连接黑屏的问题 centos 6 ...

  5. Hadoop集群的安装与配置(centos 6.5)

    一.Hadoop搭建准备(centOs6.5  且每个系统都要有同一个用户,如:hadoop)     1.IP的配置 包括Master和Slaves的IP配置,之间能够相互ping通:  例如:   ...

  6. 第2次增加ssh 主机信任脚本

    dr-mysql01:/root# cat a1.sh #用户名 uname="$1" #密码 passwd="$2" #执行检测并安装expect模块 ep= ...

  7. Android编程心得-设计一个可重用的自定义Dialog

            我们在实际开发过程中,会遇到一个问题,我们的Dialog如果使用一般的方法进行设置调用出来,会有很多的重复代码,如何将Dialog按照自己的思路设计呢,并让其可重用呢,下面我来介绍一下 ...

  8. erlang 初体验

    近期測试了一下 erlang的坑... 如不出意外.... 大家第一眼看到这语法... 心里第一句一定是"我擦.这TM都是啥!!!!!" 没有变量!!! 没有结构体!!! 没有循环 ...

  9. iOS-响应上下左右滑动手势

    -(void)viewDidLoad{ UISwipeGestureRecognizer *recognizer; recognizer = [[UISwipeGestureRecognizer al ...

  10. java--内部类实现“类的多重继承”

    class Fa1{ private int k = 1; void show() { System.out.println(k); } } class Fa2{ private int k = 10 ...