偶遇串行化 Serializer
- MD doCumEnT: 3/13/2016 6:06:17 AM by Jimbowhy
我其实是挺理解老外大胡子编程人士为何爱用“f**king code”来描述那种状态,因为有时候眼手一起码上了劲,就会真有那种感觉的啊! - by Jimbowhy, 3/13/2016 7:55:10 AM
偶遇串行化
玩 LeetCode 的过程中,无意打开了模拟面试的功能 Mock Interview,出现一条60分钟的试题,喔!串行化,作为一个编程领域必备技术,串行化的功能最能体现威力的就有远程对象传输,也就是说通过网络,将本机运程的程序对象发送给另一个正在运行的程序,是不是很棒!作为 MFC 六大核心机制之一的串行化,也用于 MFC 体系中的文件存储,总之串行化和解串行是令我兴奋的技术之一。今天就要来 LeetCode 解一解串行化的题目,原题内容:
No. 297 Serialize and Deserialize Binary Tree My Submissions Question
Total Accepted: 15172 Total Submissions: 56198 Difficulty: HardRemaining time: 38 minutes, 29 seconds.
Serialize and Deserialize Binary Tree
Difficulty: HardSerialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment.
Design an algorithm to serialize and deserialize a binary tree. There is no restriction on how your serialization/deserialization algorithm should work. You just need to ensure that a binary tree can be serialized to a string and this string can be deserialized to the original tree structure.
For example, you may serialize the following tree
1
/ \
2 3
/ \
4 5
as “[1,2,3,null,null,4,5]”, just the same as how LeetCode OJ serializes a binary tree. You do not necessarily need to follow this format, so please be creative and come up with different approaches yourself.
Note: Do not use class member/global/static variables to store states. Your serialize and deserialize algorithms should be stateless.Credits:
Special thanks to @Louis1992 for adding this problem and creating all test cases.
题目大意是,提供一个二叉树对象,实现它的串行化与解串行。边带之前的通配符试题,还有 Cross Self 等等有趣的题目,在 LeetCode 上玩的这几个星期确实让我过足了瘾!之前还用关系 Forth、Mathematica图像处理的文章未完成,做完 LeetCode 这道题就要暂停一阵了。
还有CSDN的问答,动不却就封,太不近情理了,我连因为什么原因被封的都不知道!
编码过程
这道同样是 Hard 的题目花了不少时间,借此机会熟习了一翻C++的一些常用基础类,包含用 string 来处理二进制数据,用 deque 的双向堆栈结构来处理解串行遇到的问题。deque和vector还有list组成了