class BinaryTreeEquals {

  public boolean areEqualsIterative(BinaryNode<Integer> tree1, BinaryNode<Integer> tree2) {
    validateInput(tree1, tree2);

    boolean equals = true;
    Stack<BinaryNode> stack1 = new Stack<BinaryNode>();
    Stack<BinaryNode> stack2 = new Stack<BinaryNode>();
    stack1.push(tree1);
    stack2.push(tree2);
    while (!stack1.isEmpty()) {
      BinaryNode node1 = stack1.pop();
      BinaryNode node2 = stack2.pop();
      if (!node1.equals(node2)) {
        equals = false;
        break;
      }
      addNodeToStack(stack1, node1.getLeft());
      addNodeToStack(stack1, node1.getRight());
      addNodeToStack(stack2, node2.getLeft());
      addNodeToStack(stack2, node2.getRight());
    }
    return equals;
  }

}