12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- 'use strict'
- /**
- * Definition for binary tree
- * function TreeNode(val) {
- * this.val = val;
- * this.left = this.right = null;
- * }
- */
- function TreeNode(val) {
- this.val = val;
- this.left = this.right = null;
- }
- /**
- * @constructor
- * @param {TreeNode} root - root of the binary search tree
- */
- var BSTIterator = function (root) {
- }
- /**
- * @this BSTIterator
- * @returns {boolean} - whether we have a next smallest number
- */
- BSTIterator.prototype.hasNext = function () {
- }
- /**
- * @this BSTIterator
- * @returns {number} - the next smallest number
- */
- BSTIterator.prototype.next = function () {
- }
- /**
- * Your BSTIterator will be called like this:
- * var i = new BSTIterator(root), a = [];
- * while (i.hasNext()) a.push(i.next());
- */
- function __main__() {
- /* eslit no-console: ["error", {"allow": ["log"]}] */
- const logger = console.log.bind(console)
- // 1
- // / \
- // 2 3
- // / /\
- // 4 6 7
- const n7 = new TreeLinkNode(7)
- const n6 = new TreeLinkNode(6)
- const n4 = new TreeLinkNode(4)
- const n3 = new TreeLinkNode(3)
- n3.left = n6
- n3.right = n7
- const n2 = new TreeLinkNode(2)
- n2.left = n4
- const n1 = new TreeLinkNode(1)
- n1.left = n2
- n1.right = n3
- const i = new BSTIterator(n1)
- const a = []
- while (i.hasNext()) {
- a.push(i.next())
- }
- logger(a)
- }
- __main__()
|