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的更多相关文章

  1. 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 ...

  2. 【转】Senior Data Structure · 浅谈线段树(Segment Tree)

    本文章转自洛谷 原作者: _皎月半洒花 一.简介线段树 ps: _此处以询问区间和为例.实际上线段树可以处理很多符合结合律的操作.(比如说加法,a[1]+a[2]+a[3]+a[4]=(a[1]+a[ ...

  3. [Tree]Binary Tree Inorder Traversal

    Total Accepted: 98729 Total Submissions: 261539 Difficulty: Medium Given a binary tree, return the i ...

  4. Binary Tree Postorder Traversal leetcode java

    题目: Given a binary tree, return the postorder traversal of its nodes' values. For example: Given bin ...

  5. LeetCode 589. N叉树的前序遍历(N-ary Tree Preorder Traversal)

    589. N叉树的前序遍历 589. N-ary Tree Preorder Traversal LeetCode589. N-ary Tree Preorder Traversal 题目描述 给定一 ...

  6. 【LEETCODE OJ】Binary Tree Postorder Traversal

    Problem Link: http://oj.leetcode.com/problems/binary-tree-postorder-traversal/ The post-order-traver ...

  7. Binary Search Tree In-Order Traversal Iterative Solution

    Given a binary search tree, print the elements in-order iteratively without using recursion. Note:Be ...

  8. 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 ...

  9. Binary Tree Preorder Traversal on LeetCode in Java

    二叉树的非递归前序遍历,大抵是很多人信手拈来.不屑一顾的题目罢.然而因为本人记性不好.基础太差的缘故,做这道题的时候居然自己琢磨出了一种解法,虽然谈不上创新,但简单一搜也未发现雷同,权且记录,希望于人 ...

随机推荐

  1. jquery文件上传控件 Uploadify(转)

    原文:http://www.cnblogs.com/mofish/archive/2012/11/30/2796698.html 基于jquery的文件上传控件,支持ajax无刷新上传,多个文件同时上 ...

  2. c语言字符串赋值

    char *p="asdf";能运行 定义一个字符指针,并用它指向常量字符串"asdf"的首地址 char *p;p="asdf"; 能运行 ...

  3. 给UITextField设置头或尾空白

    有时候,我们需要在UITextField的头尾加入一些空白,如下图所示: 其中,黄色和红色部分代表空白. 实现起来,比较简单,只需要设置UITextField的leftView.leftViewMod ...

  4. CentOS上yum安装Nginx服务

    一.更改yum源为网易的源加快速度 vi /etc/yum.repos.d/CentOS-Base.repo更改内容如下 # CentOS-Base.repo # # This file uses a ...

  5. java中volatile关键字的含义(转)

    在java线程并发处理中,有一个关键字volatile的使用目前存在很大的混淆,以为使用这个关键字,在进行多线程并发处理的时候就可以万事大吉. Java语言是支持多线程的,为了解决线程并发的问题,在语 ...

  6. ubuntu环境 rake aborted!

    错误: rake aborted! Gem::LoadError: You have already activated rake 10.3.2, but your Gemfile requires ...

  7. MS coco数据集下载

    2017年12月02日 23:12:11 阅读数:10411 登录ms-co-co数据集官网,一直不能进入,FQ之后开看到下载链接.有了下载链接下载还是很快的,在我这儿晚上下载,速度能达到7M/s,所 ...

  8. 在集群中使用文件加载graph

    从hdfs上加载文件并创建graph scala> var graphs = GraphLoader.edgeListFile(sc,"/tmp/dataTest/graphTest. ...

  9. oracle分区表和分区索引概述

    ㈠ 分区表技术概述            ⑴ Range 分区            ① 例子                  create table t         (...列定义...)  ...

  10. [译]GLUT教程 - 整合代码2

    Lighthouse3d.com >> GLUT Tutorial >> Input >> The Code So Far II 以下是前面几节的完整整合代码: # ...