@@ -0,0 +1,1285 @@
+package chapter_3.stack_queue;%0A%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0Apublic class SetOfStacks%3CT%3E extends AbstractStack%3CT%3E %7B%0A  private Map%3CInteger, CustomStack%3CT%3E%3E map;%0A  private int threshold = 0;%0A  private int mostRecentStack = -1;%0A%0A  public SetOfStacks(int threshold) %7B%0A    this.threshold = threshold;%0A    map = new HashMap%3CInteger, CustomStack%3CT%3E%3E();%0A  %7D%0A%0A  @Override%0A  public void push(T data) %7B%0A    CustomStack%3CT%3E stack = map.get(mostRecentStack);%0A    if (mostRecentStack == -1 %7C%7C (stack != null && stack.size() %3E threshold)) %7B%0A      stack = createStack();%0A    %7D%0A%0A    stack.push(data);%0A  %7D%0A%0A  @Override%0A  public T pop() %7B%0A    return popAt(mostRecentStack);%0A  %7D%0A%0A  @Override%0A  public T peek() %7B%0A    CustomStack%3CT%3E stack = map.get(mostRecentStack);%0A    if (stack != null) %7B%0A      return stack.peek();%0A    %7D%0A%0A    return null;%0A  %7D%0A%0A  public T popAt(int index) %7B%0A    CustomStack%3CT%3E stack = map.get(index);%0A    if (stack == null) %7B%0A      System.out.println(%22Sub-stack not found%22);%0A      return null;%0A    %7D%0A    %0A    T popped = stack.pop();%0A    if (stack.isEmpty()) %7B%0A      mostRecentStack--;%0A    %7D%0A    return popped;%0A  %7D%0A%0A  private CustomStack%3CT%3E createStack() %7B%0A    CustomStack%3CT%3E stack = new CustomStack%3CT%3E();%0A    map.put(mostRecentStack++, stack);%0A    return stack;%0A  %7D%0A%7D%0A

Add Datastructure for Set of Stacks using HashMap to track