/* * Stack.java * * Created on 13 de Maio de 2006, 14:55 * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package calcpolonesa; /** * * @author meiadmin */ public class Stack { /** Fields */ private float[] data; private int top_index; /** Creates a new instance of Stack */ public Stack(int size) { data = new float[size]; top_index = -1; } public boolean isEmpty() { return top_index < 0; } public boolean isFull() { return top_index == data.length -1; } public void push(float n) throws StackException { if( isFull() ) throw new StackException("pilha cheia"); data[++top_index] = n; } public float pop() throws StackException { if( isEmpty() ) throw new StackException("pilha vazia"); return data[top_index--]; } public float top() throws StackException { if( isEmpty() ) throw new StackException("pilha vazia"); return data[top_index]; } } class StackException extends Exception { public StackException(String msg) { super(msg); } }