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. 基于webmagic的种子网站爬取

    代码地址如下:http://www.demodashi.com/demo/12175.html 1. 概述 因为无聊,闲来没事做,故突发奇想,爬个种子,顺便学习爬虫.本文将介绍使用Spring/Myb ...

  2. LBS 附近的人

    1 http://www.infoq.com/cn/articles/depth-study-of-Symfony2 2 http://lbsyun.baidu.com/

  3. .Net 异步调用

    .NET异步编程之新利器——Task与Await.Async   一.  FrameWork 4.0之前的线程世界    在.NET FrameWork 4.0之前,如果我们使用线程.一般有以下几种方 ...

  4. nightwatchJS ---element用法

    .element() Search for an element on the page, starting from the document root. The located element w ...

  5. Spring事务管理之声明式事务管理-基于AspectJ的XML方式

    © 版权声明:本文为博主原创文章,转载请注明出处 案例 - 利用Spring的声明式事务(AspectJ)管理模拟转账过程 数据库准备 -- 创建表 CREATE TABLE `account`( ` ...

  6. Ubuntu下编译Hello World驱动并运行全过程

    一般内核驱动都是在实体机上跑的,那有没有方法在ubuntu直接编译并运行呢?带着这个问题在网上查了一些资料,之后就实现了. 运行 hello.c   #include<linux/init.h& ...

  7. rbg大神的主页

    http://www.rossgirshick.info/ Ross Girshick (rbg)Research ScientistFacebook AI Research (FAIR) r...@ ...

  8. [译]NeHe教程 - 创建一个OpenGL窗体

    原文: Setting Up An OpenGL Window 欢迎阅读我的OpenGL教程.我是一个热爱OpenGL的普通码农!我第一次听到OpenGL是在3Dfx刚发布他们给Voodoo I显卡的 ...

  9. Memcached下载、安装及使用演示。

    Memcached下载及安装: 下载地址: memcached-1.4.5-amd64.zip================================================通过cmd ...

  10. HDU3351 Seinfeld 【贪心】

    Seinfeld Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...