public List<BinaryNode> getIterative(BinaryNode root) {
    validateBinaryNode(root);
    List<BinaryNode> result = new LinkedList<BinaryNode>();
    Stack<BinaryNode> stack = new Stack<BinaryNode>();
    stack.push(root);

    while (!stack.isEmpty()) {
      BinaryNode node = stack.pop();
      result.add(node);
      if (node.hasRight()) {
        stack.add(node.getRight());
      }
      if (node.hasLeft()) {
        stack.add(node.getLeft());
      }
    }

    return result;
  }
Iterative implementation of this binary tree traversal. The complexity order in time terms of
this algorithm is O(N) where N is the number of nodes in the tree. In space terms the
complexity order of this algorithm is also O(N) where N is the number of nodes we have to
store in the auxiliary data structure, the stack.
src/main/java/com/github/pedrovgs/problem14/BinaryTreePreOrder.java