Пример #1
0
 // 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;
 }
Пример #2
0
 public Stack<T> concat(Stack<T> stack) {
   Stack<T> rv = this;
   for (T elt : stack) {
     rv = rv.push(elt);
   }
   return rv;
 }
Пример #3
0
 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;
 }
Пример #4
0
 protected Stack<T> reverseImpl(Stack<T> stack) {
   return tail.reverseImpl(stack.push(head));
 }