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

  let nodeStack = []
  nodeStack.push(root)

  while (nodeStack.length) {
    var node = nodeStack.pop()

    result.push(node.val)

    if (node.right) {
      nodeStack.push(node.right)
    }

    if (node.left) {
      nodeStack.push(node.left)
    }
  }

  return result
}

module.exports = traversePreOrderIterative
