码迷,mamicode.com
首页 >  
搜索关键字:levelorder    ( 32个结果
数据结构:树的BFS,树的层次遍历! 按先序遍历创建一棵树,然后以层次遍历输出。
按先序遍历创建一棵树,以层次遍历输出 样例输入 A B # D # # C E # # F # # 样例输出 LevelOrder: A B C D E F     代码: #include #include using namespace std; struct node { //表示一个树上的节点 char ch; nod...
分类:其他好文   时间:2014-06-10 15:58:02    阅读次数:295
Leetcode 树 Binary Tree Level Order Traversal
题意:给定一棵二叉树,返回按层遍历的结果 思路1:bfs,定义一个新的struct,记录指针向节点的指针和每个节点所在的层 复杂度1:时间O(n),空间O(n) 思路2:dfs 递归函数: void levelOrder(TreeNode *root, int level, vector<vector >&result) 表示把根为root的树按层存放在result中,其中level表示当前的层数 复杂度2:时间O(n),空间O(n) 相关题目:...
分类:其他好文   时间:2014-05-15 14:46:06    阅读次数:355
32条   上一页 1 2 3 4
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!