@@ -0,0 +1,969 @@
+import java.util.*;%0A%0Apublic class Problem3_3 %7B%0A%0A  public static void main(String%5B%5D args) %7B%0A    SetOfStacks%3CInteger%3E stack = new SetOfStacks%3C%3E(5);%0A%0A    for (int i = 0; i %3C 40; i++) %7B%0A      stack.push(i);%0A    %7D%0A%0A    for (int i = 39; i %3E= 0; i--) %7B%0A      System.out.println(stack.pop() + %22 should be %22 + i);%0A    %7D%0A  %7D%0A%0A  static class SetOfStacks%3CT%3E %7B%0A    LinkedList%3CLinkedList%3CT%3E%3E stacks = new LinkedList%3C%3E();%0A    int cap;%0A%0A    public SetOfStacks(int cap) %7B%0A      this.cap = cap;%0A    %7D%0A%0A    public T pop() %7B%0A      LinkedList%3CT%3E top = stacks.peek();%0A      if (top == null) %7B%0A        throw new IllegalStateException(%22Nothing left!%22);%0A      %7D%0A      T ret = top.pop();%0A      if (top.peek() == null) %7B%0A        stacks.pop();%0A      %7D%0A      return ret;%0A    %7D%0A%0A    public void push(T val) %7B%0A      LinkedList%3CT%3E top = stacks.peek();%0A      if (top == null %7C%7C top.size() %3E= cap) %7B%0A        top = new LinkedList%3C%3E();%0A        stacks.push(top);%0A      %7D%0A      top.push(val);%0A    %7D%0A%0A  %7D%0A%0A%7D%0A

Set of stacks (3_3)