Pretty print binary tree
来源:互联网 发布:arm单片机型号 编辑:程序博客网 时间:2024/05/16 11:32
http://articles.leetcode.com/2010/09/how-to-pretty-print-binary-tree.html
简化版本的C++
const int box_size = 3;std::queue q;q.push(m_root);size_t current_level_nodes = 1;size_t next_current_level_nodes = 0;size_t level = 1;int padding = box_size * (std::pow(2, Height() - level) - 1);std::cout << std::setw(padding / 2) << "";while (level <= Height()){std::cout << std::setw(box_size);if (q.front() != NULL){std::cout <<q>get_val();q.push(q.front()->get_left());q.push(q.front()->get_right());}else{std::cout << "";q.push(NULL);q.push(NULL);}next_current_level_nodes += 2;std::cout << std::setw(padding) << "";q.pop();--current_level_nodes;if (current_level_nodes == 0){current_level_nodes = next_current_level_nodes;next_current_level_nodes = 0;++level;padding = box_size * (std::pow(2, Height() - level) - 1);std::cout << "\n" << std::setw(padding / 2) << "";}}
0 0
- Pretty print binary tree
- print binary tree boundary
- Print binary tree
- 655. Print Binary Tree
- 655. Print Binary Tree
- 655. Print Binary Tree
- Leetcode655. Print Binary Tree
- LeetCode Print Binary Tree
- 655. Print Binary Tree
- Print Binary Tree
- LeetCode_655. Print Binary Tree
- 655. Print Binary Tree
- clockwise print binary search tree
- Leetcode--655. Print Binary Tree
- leetcode 655. Print Binary Tree
- js的pretty print
- Print Boundry Nodes of a binary tree.
- Print Binary Tree问题及解法
- LeetCode(026) Remove Duplicates from Sorted Array (Java)
- LeetCode - Candy
- UI 界面的编写工作,到底应该用 xib/storyboard 完成,还是用手写代码来完成?
- java反射机制
- 单片机的烧写原理
- Pretty print binary tree
- [Leetcode] 140. Work Break II
- Python 传递可变长参数
- windows下安装apache及php需要注意的问题
- 嵌入式 linux 第四课 内存管理单元MMU
- Decode Ways
- 如何解析SDP中包含的H.264的SPS和PPS串
- css滑动门技术
- hadoop 不使用hostname,使用ip遇到的问题(Datanode denied communication with namenode because hostname cann)及解决方案