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. C#堆栈

    栈就是堆栈,因为堆和堆栈这样说太拗口了,搞得像绕口令,所以有些时候就把堆栈简称为栈.堆和栈,你看这又多舒服. 但无论什么时候,堆栈都不等于堆和栈,必须说,堆和栈或者堆和堆栈. 有人说:“C#的所有值类 ...

  2. 使用SourceTree Push 出现 POST git-receive-pack (chunked) 的解决方法

    在使用SourceTree上传资料的时候,遇到 POST git-receive-pack (chunked) 从 stackoverflow 看到这样一则 This is a bug in Git; ...

  3. qml+opencv(二),实现人脸检测

    http://blog.csdn.net/zhx6044/article/details/45048765

  4. 基于Sql Server 2008的分布式数据库的实践(四)

    原文 基于Sql Server 2008的分布式数据库的实践(四) 数据库设计 1.E-R图 2.数据库创建 Win 7 1 create database V3 Win 2003 1 create  ...

  5. GUI动态创建button

    #include "cocos2d.h" #include "cocos-ext.h" USING_NS_CC; USING_NS_CC_EXT; using ...

  6. 使用gson(一)

    1.数组和json的转换 package com.test.gson; import com.google.gson.Gson; public class ArrayToJson { public s ...

  7. 网页制作之JavaScript部分 1 - 语法(复制教材内容)

    一.简介 1.JavaScript它是个什么东西? 它是个脚本语言,需要有宿主文件,他的宿主文件是html文件. 2.它与Java有什么关系? 没有什么直接联系,java是Sun公司(已经没有了,被O ...

  8. Mars的mp3实例

    Mars的mp3实例第一课: 关于menu: package mars.mp3player01; import mars.down.HttpDownloader; import android.app ...

  9. [转]VMware 出现下述错误: Application failure. hr=0x80040101:Failed to initialize virtual machine.

    VMware 出现下述错误:Application failure. hr=0x80040101:Failed to initialize virtual machine. 解决方法:1.重新注册这三 ...

  10. ie6背景透明的设置方法 ie6背景颜色透明和png图像透明解决方法

    IE6浏览器,让我们又爱又恨.爱它的是,可以让我们写的代码的时候,可以更标准,恨的是,它有太多无厘头的IE6常见bug(详情点击),让我们焦头烂额.现在现在用百度浏览器调查,国内占有率不到6%了,但是 ...