public int compare(Stack<T> arg0, Stack<T> arg1) { if (arg0.isEmpty()) { return arg1.isEmpty() ? 0 : -1; } else { if (arg1.isEmpty()) return 1; int rv = arg0.head().compareTo(arg1.head()); return rv == 0 ? compare(arg0.tail(), arg1.tail()) : rv; } }
public boolean hasNext() { return !stack.isEmpty(); }
// Warning, uses equals to test for containment. public boolean contains(Stack<T> stack) { if (stack.isEmpty()) return true; if (isEmpty()) return false; // stack is not empty return head().equals(stack.head()) ? tail().contains(stack.tail()) : false; }