Print Boundry Nodes of a binary tree.
2016-06-16 05:11
507 查看
void printLeaves(TreeNode* root) { if(root) { printLeaves(root->left); if(!(root->left) && !(root->right)) cout << root->val << endl; printLeaves(root->right); } } void PrintBoundryRight(TreeNode* root) { if(root) { if(root->right) { PrintBoundryRight(root->right); cout << root->val << endl; } else if(root->left) { PrintBoundryRight(root->left); cout << root->val << endl; } } } void PrintBoundryLeft(TreeNode* root) { if(root) { if(root->left) { cout << root->val << endl; PrintBoundryLeft(root->left); } else if(root->right) { cout << root->val << endl; PrintBoundryLeft(root->right); } } } void printBoundry(TreeNode* root) { if(!root) return; cout << root->val << endl; PrintBoundryLeft(root->left); printLeaves(root->left); printLeaves(root->right); PrintBoundryRight(root->right); }
相关文章推荐
- Node request pipe
- Node request
- erlang remote node
- 测试框架:ava
- NodeJs使用asyncAwait两法
- 从node.js想到的
- node定时器详解
- node.js 安装cnpm nodemon express pm2 node-inspector
- nodejs websocket 把下面错误
- node.js npm 配置相关
- node-webkit 笔记
- Node && Express 学习日记(第一天)
- ccah-500 第39题 How must you format underlying file system of each DataNode
- ubuntu deepin安装node.js和npm
- NodeJS、NPM安装配置步骤(windows版本) 转
- node.js在windows下服务不成功
- Node.js中, 使用Q.ninvoke封装对象方法为promise
- ccah-500 第35题 What do you have to do on the cluster to allow the worker node to join
- ccah-500 第34题 you want to change a configuration parameter so that it affects all six DataNodes
- 19. Remove Nth Node From End of List