const traverseInOrderIterative = (root) => {
  let result = []

  var current = root,
    s = [],
    done = false

  while (!done) {
    // Reach the left most Node of the current Node
    if (current != null) {
      // Place pointer to a tree node on the stack
      // before traversing the node's left subtree
      s.push(current)
      current = current.left
    } else {
      if (s.length) {
        current = s.pop()
        result.push(current.val)
        current = current.right
      } else {
        done = true
      }
    }
  }

  return result
}

module.exports = traverseInOrderIterative
