// Too bad Java doesn't support generic arrays or varargs public static Stack<String> makeName(String... strings) { Stack<String> rv = Stack.<String>emptyInstance(); for (int i = strings.length - 1; i >= 0; i--) { rv = rv.push(strings[i]); } return rv; }
public Stack<T> concat(Stack<T> stack) { Stack<T> rv = this; for (T elt : stack) { rv = rv.push(elt); } return rv; }
public Stack<T> addUnique(Stack<T> stack) { Stack<T> rv = this; for (T elt : stack) { if (rv.contains(elt)) continue; rv = rv.push(elt); } return rv; }
protected Stack<T> reverseImpl(Stack<T> stack) { return tail.reverseImpl(stack.push(head)); }