Print nodes in a given range of BST
2016-06-07 06:17
316 查看
I am stupid..... this is a MS interview question.
Pseudo code
Pseudo code
void printNode(root) { if(!root) return; stack<Node*> nodes; Node* pCurrent; while(!pCurrent || !nodes.empty()) { if(pCurrent) { nodes.push(pCurrent); Node* tmp = nodes.top(); if(tmp->val < small) {root = NULL;} else { pCurrent = pCurrent->left; } } else { Node* top = stack.top(); stack.pop(); if(top->val >= small && top->val <= big) cout << top->val << endl; if(top->val > big) pCurrent = NULL; else pCurrent = top->right; } } }
相关文章推荐
- NodeJS 不可逆加密与密码密文保存
- leecode_222 Count Complete Tree Nodes
- DrawNode绘制几何图形
- node.js 和 express 框架学习笔记(2)
- node js 获取ip
- javascript中children和childNodes的区别
- Study NodeJS《NPM常用命令》
- 【LeetCode】011 Swap Nodes in Pairs 两两换位
- 《Nodejs开发加密货币》之十七:共识机制,可编程的利益转移规则
- ambari回滚 禁止namenode ha
- Folk博客程序——可以运行于node环境和asp环境的博客系统
- node定时任务
- inode与super block
- BAE log服务的配置(nodejs)
- 6个讨喜的 ES6 小技巧
- Node学习笔记(三):基于socket.io web版你画我猜(二)
- 【leetcode】25. Reverse Nodes in k-Group
- Node.js的Web模板引擎ejs的入门使用教程
- 关于nodejs邮件群发的Nodemailer
- nodejs 的 session 简单使用