Data Structure Binary Tree: Boundary Traversal of binary tree
http://www.geeksforgeeks.org/boundary-traversal-of-binary-tree/
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <fstream>
#include <map>
using namespace std; struct node {
int data;
struct node *left, *right;
node() : data(), left(NULL), right(NULL) { }
node(int d) : data(d), left(NULL), right(NULL) { }
}; void printleft(node *root) {
if (!root) return;
if (root->left) {
cout << root->data << " ";
printleft(root->left);
}
else if (root->right) {
cout << root->data << " ";
printleft(root->right);
}
} void printleaf(node *root) {
if (!root) return;
printleaf(root->left);
if (!root->left && !root->right) cout << root->data << " ";
printleaf(root->right);
} void printright(node *root) {
if (!root) return;
if (root->right) {
printright(root->right);
cout << root->data << " ";
}
else if (root->left) {
printright(root->left);
cout << root->data << " ";
}
} void printboundary(node *root) {
if (!root) return;
cout << root->data << " ";
printleft(root->left);
printleaf(root);
printright(root->right);
} int main() {
node *root = new node();
root->left = new node();
root->right = new node();
root->left->left = new node();
root->left->right = new node();
root->right->right = new node();
root->left->right->left = new node();
root->left->right->right = new node();
printboundary(root);
return ;
}
Data Structure Binary Tree: Boundary Traversal of binary tree的更多相关文章
- Binary Tree Preorder Traversal and Binary Tree Postorder Traversal
Binary Tree Preorder Traversal Given a binary tree, return the preorder traversal of its nodes' valu ...
- 【转】Senior Data Structure · 浅谈线段树(Segment Tree)
本文章转自洛谷 原作者: _皎月半洒花 一.简介线段树 ps: _此处以询问区间和为例.实际上线段树可以处理很多符合结合律的操作.(比如说加法,a[1]+a[2]+a[3]+a[4]=(a[1]+a[ ...
- [Tree]Binary Tree Inorder Traversal
Total Accepted: 98729 Total Submissions: 261539 Difficulty: Medium Given a binary tree, return the i ...
- Binary Tree Postorder Traversal leetcode java
题目: Given a binary tree, return the postorder traversal of its nodes' values. For example: Given bin ...
- LeetCode 589. N叉树的前序遍历(N-ary Tree Preorder Traversal)
589. N叉树的前序遍历 589. N-ary Tree Preorder Traversal LeetCode589. N-ary Tree Preorder Traversal 题目描述 给定一 ...
- 【LEETCODE OJ】Binary Tree Postorder Traversal
Problem Link: http://oj.leetcode.com/problems/binary-tree-postorder-traversal/ The post-order-traver ...
- Binary Search Tree In-Order Traversal Iterative Solution
Given a binary search tree, print the elements in-order iteratively without using recursion. Note:Be ...
- LeetCode:Construct Binary Tree from Inorder and Postorder Traversal,Construct Binary Tree from Preorder and Inorder Traversal
LeetCode:Construct Binary Tree from Inorder and Postorder Traversal Given inorder and postorder trav ...
- Binary Tree Preorder Traversal on LeetCode in Java
二叉树的非递归前序遍历,大抵是很多人信手拈来.不屑一顾的题目罢.然而因为本人记性不好.基础太差的缘故,做这道题的时候居然自己琢磨出了一种解法,虽然谈不上创新,但简单一搜也未发现雷同,权且记录,希望于人 ...
随机推荐
- 基于React的PC网站前端架构分析
代码地址如下:http://www.demodashi.com/demo/12252.html 本文适合对象 有过一定开发经验的初级前端工程师: 有过完整项目的开发经验,不论大小: 对node有所了解 ...
- 用python做自己主动化測试--绘制系统性能趋势图和科学计算
在性能測试中.我们常常须要画出CPU memory 或者IO的趋势图. 预计大学里.大多数人都学习过matlib, 领略了matlib绘图的强大. python提供了强大的绘图模块matplotlib ...
- Hive命令行经常使用操作(数据库操作,表操作)
数据库操作 查看全部的数据库 hive> show databases ; 使用数据库default hive> use default; 查看数据库信息 hive > descri ...
- CentOS上yum安装Nginx服务
一.更改yum源为网易的源加快速度 vi /etc/yum.repos.d/CentOS-Base.repo更改内容如下 # CentOS-Base.repo # # This file uses a ...
- github上比較好的开源项目(持续更新)
1:https://github.com/Skykai521/StickerCamera 实现相机功能 实现对图片进行裁剪的功能 图片的滤镜功能 能为图片加入贴纸(贴纸可移动,放大,旋转) 能为图片加 ...
- RTM-DSP项目总结
1. 项目介绍 在NINJA设备上支持RTM-ISDN卡 RTM-ISDN卡硬件组成 主要组成单元 C6415: DSP PEB383(上图中的PEX8112改为PEB383,由于后者具有NT功能) ...
- IIS7设置默认页
一般用ASP.NET创建的网站默认页都是Default.aspx,不需要设置. 但是如果有网站的起始页不是Default.aspx,就需要在IIS里设置了. IIS7的设置方法和IIS6的不一样: 在 ...
- do{}while(0)与CC_BREAK_IF的绝妙搭配
从一開始认为没有必要,到认为很好用.我经历了大概两个月的时间,以下来总结一下什么情况下使用这样的结构吧. 第一种情况:当载入文件的时候,假设载入文件失败,须要报错的时候. 当前,能够用try{}cat ...
- Gradle 的配置和引用
我们的Android studio工程有时会存在很多共同的构建包 这里我会新建一个gradle 文件 config.gradle ext{ android = [ applicationId : &q ...
- 002android初级篇之ViewPager及PagerSlidingTabStrip listview的使用
002android初级篇之ViewPager及PagerSlidingTabStrip listview的使用 ViewPager ViewPager类直接继承了ViewGroup类,所有它是一个容 ...