public static boolean areEqual(MyStack<String> stack1,
			MyStack<String> stack2) {
		/* same object */
		if (stack1.equals(stack2)) {
			return true;
		}

		boolean flag = false;
		MyStack<String> temp = new ArrayStack<String>();

		/* compare elements from two stacks */
		while (!stack1.isEmpty() && !stack2.isEmpty()) {
			if (!stack1.peek().equals(stack2.peek())) {
				break;
			}
			/* push into a temp stack */
			temp.push(stack1.pop());
			temp.push(stack2.pop());
		}

		/* two stacks have same number of elements */
		if (stack1.isEmpty() && stack2.isEmpty()) {
			flag = true;
		}

		/* restore two stacks */
		while (!temp.isEmpty()) {
			stack2.push(temp.pop());
			stack1.push(temp.pop());
		}

		return flag;
	}