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 ...
随机推荐
- c++,类的组合
1. 在A类中以B类的对象作为成员变量,称为类的组合(composition). 可以先看看这篇文章理解组合的用处: C++中组合的使用 http://blog.csdn.net/jia_xiaoxi ...
- c++,static 静态成员变量 / 静态成员函数
静态成员变量: //静态成员变量(static) // //1.如果想在同类的多个对象之间实现数据共享 ,可以用静态 //成员变量,即用static修饰的成员变量,例 static int a; // ...
- CentOS下配置多个Tomcat同时运行 本篇文章来源于 Linux公社网站(www.linuxidc.com)
原文地址:http://blog.csdn.net/tjcyjd/article/details/46553361 版权声明:本文为博主原创文章,未经博主允许不得转载. 同一服务器部署多个tomcat ...
- Linux 下github的使用
*初始化git仓库,使用git init命令 *添加文件到git仓库分两步: 1.使用git add filename :可分多次使用,添加多个文件到暂存区 2.使用git commit -m “ ...
- 动态加载EXE和DLL
程序中加载了一个DLL文件,但生成的EXE在脱离了DLL文件后仍然可以 单独使用,这是动态加载DLL技术.即:调用资源中的DLL. 此技术的好处:EXE可以使用DLL中的函数,但不会额外增加一 个DL ...
- 前端SEO优化
结构优化 1.扁平化结构,目录层次越少越好
- 通过xml生成word文档
Xml生成word总结 使用xml生成word的基本步骤在<使用xslt转化xml数据形成word文档导出.doc>中说明比较清楚了.但是其中的细节并未说到,因此自己折腾了两天总算成功了. ...
- 【译】在ASP.NET中创建PDF-iTextSharp起步
原文 [译]在ASP.NET中创建PDF-iTextSharp起步 .Net framework 中自身并不包含可以和pdf打交道的方法.所以,当你需要你的ASP.Net Web应用程序中包含创建或与 ...
- Windows Azure 社区新闻综述(#78 版)
欢迎查看最新版本的每周综述,其中包含有关云计算和 Windows Azure 的社区推动新闻.内容和对话.以下是本周的亮点. 博客文章: 博客:Windows Azure BizTalk 服务:如何开 ...
- WOJ 1014
#include<stdio.h> #include<stdlib.h> #include<math.h> int main() { double a[3][3]= ...