/* * @(#)Stack.java 1.13 98/09/11 * * Copyright 1998 Elliotte Rusty Harold. * * Permission to use, copy, modify, and distribute this software * and its documentation for all purposes and without * fee is hereby granted provided that this copyright notice * appears in all copies. */ package java.util; /** * A stack that guarantees its own integrity. * * @version 1.0, 12/09/96 * @author Elliotte Rusty Harold */ public class Stack { Vector theStack; public Object push(Object o) { theStack.addElement(o); return o; } public Object pop() { Object o; int len = theStack.size(); o = peek(); theStack.removeElementAt(len - 1); return o; } public Object peek() { Object o; int len = theStack.size(); if (len == 0) throw new EmptyStackException(); return theStack.elementAt(len - 1); } public boolean empty() { if (theStack.size() == 0) return true; else return false; } public int search(Object o) { int i = theStack.lastIndexOf(o); if (i >= 0) return theStack.size() - i; return -1; } }