Serialize a Binary Tree or a General Tree
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的更多相关文章
- 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 ...
- 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, ...
- 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 ...
- 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 ...
- 145. Binary Tree Postorder Traversal (Stack, Tree)
Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary ...
- LeetCode -- 1038. Binary Search Tree to Greater Sum Tree
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode ...
- 【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 ...
- 【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 ...
- 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 ...
随机推荐
- 解决 Xcode7 中多个模拟器的办法
转自: http://www.oschina.net/code/snippet_196012_50574 1.关闭xcode 2.终端输入 sudo killall -9 com.apple.Core ...
- c++ ,protected 和 private修饰的构造函数
c++ protected 和 private修饰的构造函数: 1.在类的外部创建对象时,不能调用protected或private修饰的构造函数. 2.当子类中的构造函数调用父类的private构造 ...
- 4.1 技术原理 & 4.2 键盘过滤框架
4.1 技术原理 & 4.2 键盘过滤框架 4.1 预备知识 符号链接:符号链接其实就是一个“别名”.可以用一个不同的名字来代表一个设备对象(实际上),符号链接可以指向任何有名字的对象. Zw ...
- 乐观锁&悲观锁
悲观&乐观,只是对数据加锁的时机与粒度. 悲观锁(Pessimistic Lock), 顾名思义,就是很悲观,每次去拿数据的时候都认为别人会修改,所以每次在拿数据的时候都会上锁,这样别人想拿这 ...
- Hbuilder主页面控制子页面的方法
主页面的写法 (function($, doc) { mui.init({ swipeBack : false, ...
- windows下各个浏览器用html5进行h.264大视频播放的性能对比说明
最近在调查windows下哪种浏览器进行大视频播放时候稳定性比较高. 举h.264的4g的视频为例. 选用的浏览器有ie10,firefox,chrome.(因为opera不支持h.264所以没有考虑 ...
- Computer Transformation(规律,大数打表)
Computer Transformation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...
- Java之GUI编程(一)
GUI全称Graphical User Interfaces,意为图形用户户界面,又称为图形用户接口.GUI指的就是採用图形方式显示的计算机操作用户界面,打个例如吧.我们点击QQ图标,就会弹出一个QQ ...
- jQuery(expression, [context]) , $(即jQuery)的參数问题
jQuery(expression, [context]) 返回值:jQuery 概述 这个函数接收一个包括 CSS 选择器的字符串,然后用这个字符串去匹配一组元素. jQuery 的 ...
- JAVA类(上)
package test; public class staticAccess { public int age; public staticAccess grow() { age++; return ...