public void push(double x) {
        if (index+1 == stack.length) {
            for (int i=0; i<stack.length-1; i++) {
                stack[i] = stack[i+1];
                index = i;
            }
        }
        stack[++index] = x;
    }