@@ -0,0 +1,1682 @@
+package com.ttaylorr.ctci.answers.stacks;%0A%0Aimport com.ttaylorr.ctci.meta.Solution;%0A%0A@Solution(chapter = 3, problem = 1)%0Apublic class ArrayStacks %7B%0A    public static final int STACK_SIZE = 128;%0A%0A    /**%0A     * To implement several stacks using one array, we will chunk the array into %60n%60%0A     * pieces and use those chunks to represent each stack.%0A     */%0A    protected Object%5B%5D arr;%0A%0A    /**%0A     * To keep track of where the head of that stack is within each array, we will%0A     * store off an %22offset%22 pointer to tell us where the head of the stack is, relative%0A     * to n * stack_size.%0A     *%0A     * For example: the head of stack 6 is:%0A     *      int head = (6 * stackSize) + this.pointers%5B6%5D + 1;%0A     */%0A    protected final int%5B%5D pointers;%0A%0A    public ArrayStacks(int numStacks) %7B%0A        assert numStacks %3E 0;%0A        this.arr = new Object%5BSTACK_SIZE * numStacks%5D;%0A        this.pointers = new int%5BnumStacks%5D;%0A    %7D%0A%0A    public void push(int stack, Object o) %7B%0A        int index = stack * STACK_SIZE + this.pointers%5Bstack%5D + 1;%0A        this.pointers%5Bstack%5D++;%0A        this.arr%5Bindex%5D = o;%0A    %7D%0A%0A    public Object pop(int stack) %7B%0A        // Determine the index at the head of the stack for the one we are asking for%0A        int index = stack * STACK_SIZE + this.pointers%5Bstack%5D;%0A%0A        // Grab the value we want and store it off in a local so we can later return it%0A        // Then null out the value that was in its place%0A        Object value = this.arr%5Bindex%5D;%0A        this.arr%5Bindex%5D = null;%0A%0A        // Decrement the pointer because we have removed an element from that stack%0A        this.pointers%5Bstack%5D--;%0A%0A        // Finally, return.%0A        return value;%0A    %7D%0A%7D%0A

Add the array stacks problem