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 ;
}

最新文章

  1. mac上的git环境配置
  2. [Ng]Angular应用点概览
  3. 使用WinDbg调试SQL Server——入门
  4. [Hibernate] - Interceptors and events
  5. [kuangbin带你飞]专题九 连通图
  6. win7 C# winForm编程 savefiledialog 不能弹出保存窗体
  7. JS里面匿名函数的调用 &amp; 变量作用域的实验
  8. codeforces 680B B. Bear and Finding Criminals(水题)
  9. VBA.NET 系统可行性分析模板
  10. 【转】priority_queue优先队列
  11. Fiddler抓包【7】_次要功能和第三方插件
  12. Linux将rm命令设置为回收站【转】
  13. html5 javascript 表单练习案例
  14. 洛谷P2053 修车
  15. 【colaboratory】ModuleNotFoundError: No module named &#39;forward&#39;
  16. PHP安全性考虑
  17. java线程池(一)
  18. 【uoj#164】[清华集训2015]V 线段树维护历史最值
  19. C++ 函数的扩展②
  20. colspan和rowspan合并单元格

热门文章

  1. 奥巴马(Obama)获胜演讲全文[中英对照]+高清视频下载
  2. unity4.6 Beta版 UI控件之Button
  3. mysql负载飙高原因分析
  4. 支付宝开放平台 配置RSA(SHA1)密钥 OpenSSL配置公钥私钥对
  5. [译]GLUT教程 - 创建和关闭子窗体
  6. Android使用SQLite数据库
  7. simple_pool对象池——优化&amp;lt;二&amp;gt;
  8. wps文档怎样去除广告
  9. iOS中 HTTP/Socket/TCP/IP通信协议具体解释 韩俊强的博客
  10. Linux进程间通信(一) - 管道