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 ...
随机推荐
- ios8.1上运行程序,程序界面只显示一部分
在ios 9.1上运行程序没问题 但是在8.1上运行发现模拟器上只显示了程序的一小部分界面,没有显示完全. 结果发现由以下代码设置问题引起的 - (BOOL)application:(UIApplic ...
- ELK 之二:ElasticSearch 和Logstash高级使用
一:文档 官方文档地址:1.x版本和2.x版本 https://www.elastic.co/guide/en/elasticsearch/guide/index.html 硬件要求: 1.内存,官方 ...
- 基于visual Studio2013解决C语言竞赛题之0501挑选素数
题目
- jQuery动态添加删除select项
// 添加 function col_add() { var selObj = $("#mySelect"); var value="value"; var t ...
- Android的BUG(三) - 广为人知的诟病:频繁重启问题
使用过Android的同学,尤其是用过山寨pad,应该对Android的重启问题印象深刻吧.Android由于其设计的复杂性,可能会使得系统在不经意时陷入异常状态,因此Android设计了一套看门狗机 ...
- 自己定义progressdialog,改善用户体验
自己定义progressdialog,改善用户体验 效果图: 详细实现方式: 1.定义Dialog的Layout布局 2.设置动画anim 3.创建自己定义dialog的样式 4.创建共同拥有方法来控 ...
- Winform ErrorProvider控件使用
要实现的功能:判断第一个文本框中输入的是不是字符 “a”. 最终效果: *当输入的不是a,控件旁会显示错误图标.当输入的是a,则错误图标会消失. 首先添加ErrorProvider控件. 代码: pr ...
- 第一个hibernate文件 xml配置方法
package com.entity; public class User { private String username; private String password; private In ...
- 分享非常有用的Java程序 (关键代码) (一)
原文:分享非常有用的Java程序 (关键代码) (一) 分享一些非常有用的Java程序 (关键代码) ,希望对你有所帮助. 1. 得到当前方法的名字 String methodName = Th ...
- WCF技术剖析之二十二: 深入剖析WCF底层异常处理框架实现原理[中篇]
原文:WCF技术剖析之二十二: 深入剖析WCF底层异常处理框架实现原理[中篇] 在[上篇]中,我们分别站在消息交换和编程的角度介绍了SOAP Fault和FaultException异常.在服务执行过 ...