原题地址递归写法谁都会,看看非递归写法。对于二叉树的前序和中序遍历的非递归写法都很简单,只需要一个最普通的栈即可实现,唯独后续遍历有点麻烦,如果不借助额外变量没法记住究竟遍历了几个儿子。所以,最直接的想法就是在栈中记录到底遍历了几个儿子。代码: 1 vector postorderTraversal...
分类:
其他好文 时间:
2015-01-19 18:40:29
阅读次数:
116
预备知识:
fstream提供了三个类,用来实现c++对文件的操作。(文件的创建、读、写)。
ifstream -- 从已有的文件读
ofstream -- 向文件写内容
fstream -- 打开文件供读写
文件打开模式:
ios::in 读
ios::out 写
ios::app 从文件末尾开始写
ios::binary 二进制模式
ios::nocreate ...
分类:
编程语言 时间:
2015-01-19 17:17:42
阅读次数:
182
Data Structures 基本数据结构Dictionaries 字典Priority Queues 堆Graph Data Structures 图Set Data Structures 集合Kd-Trees 线段树Numerical Problems 数值问题Solving Linear E...
分类:
其他好文 时间:
2015-01-19 14:10:41
阅读次数:
312
方法1)select * from mytable order by CONVERT(chineseColumnName USING gbk); (备注:chineseColumnName 位排序字段)方法2)对于包含中文的字段加上"binary"属性,使之作为二进制比较,例如将"name char...
分类:
数据库 时间:
2015-01-19 12:44:22
阅读次数:
183
Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that shares the same parent node) or empty, flip it up...
分类:
其他好文 时间:
2015-01-19 09:07:58
阅读次数:
134
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ ...
分类:
其他好文 时间:
2015-01-19 00:09:50
阅读次数:
174
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical an...
分类:
其他好文 时间:
2015-01-19 00:06:07
阅读次数:
241
二叉查找树(Binary Search Tree),也称二叉搜索树、有序二叉树(ordered binary tree),排序二叉树(sorted binary tree),是指一棵空树或者具有下列性质的二叉树:...
分类:
其他好文 时间:
2015-01-18 22:45:47
阅读次数:
336
(http://leetcode.com/2010/11/convert-sorted-list-to-balanced-binary.html)Given a singly linked list where elements are sorted in ascending order, conv...
分类:
其他好文 时间:
2015-01-18 22:18:49
阅读次数:
202
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.思路:题目看上去好像很难,但实际上很简单,递归做就行,每次找到左右子树对应的子链表...
分类:
其他好文 时间:
2015-01-18 21:03:17
阅读次数:
241