import java.io.*;

public class Stack {

    private final int MAX = 1000;
    private int max =  10;

    private char[]   stack;
    private  int   top;

    Stack(){
	top = 0;
	stack = new char[max];
    }

    public void  Push(char c){
	if(top < stack.length - 1){
	    stack[top++] = c;
	} else {
	    renew();
	    stack[top++] = c;
	}
    }

    public char Pop() {
	if (top > 0){
	    return stack[--top];
	} else {
	    System.out.println("Stack underflow...exiting");
	    System.exit(1);
	    return (char) 0;
	}
    }

    public boolean Empty() {
	return (top == 0);
    }

    private void renew(){
	char tmp[];
	int tmpmax = max;
	tmp = new  char[max];
	for(int i = 0; i < max; i++){
	    tmp[i] = stack[i];
	}
	if(max < MAX){
	    max = max * 2;
	} else {
	    max = max + MAX;
	}
	System.out.println("Renewing...max = " + max);
	stack = new char[max];
	for(int i = 0; i < tmpmax; i++){
	    stack[i] = tmp[i];
	}
    }
	    


}
