/** * Copyright (c): Uwe Schmidt, FH Wedel * * You may study, modify and distribute this source code * FOR NON-COMMERCIAL PURPOSES ONLY. * This copyright message has to remain unchanged. * * Note that this document is provided 'as is', * WITHOUT WARRANTY of any kind either expressed or implied. */ /** * * @author Uwe Schmidt * * eine erweiterte Vektorklasse * die zusaetzlich die StackInterface Schnittstelle * implementiert * */ //-------------------- public class Stack2 extends java.util.Vector implements StackInterface { //-------------------- // der Konstruktor public Stack2() { super(); } //-------------------- // die Funktionsruempfe // diese werden mit Operationen aus // der Basisklasse implementiert //-------------------- // public boolean isEmpty() // gibt es schon //-------------------- public Object top() { assert preTop() : "Stack2.top: empty stack"; return lastElement(); } //-------------------- public void push(Object o) { addElement(o); } //-------------------- public void pop() { assert prePop() : "Stack2.pop: empty stack"; removeElementAt(elementCount-1); } //-------------------- // // auch die Vorbedingungen muessen implementiert werden // Gefahr: Codeverdopplung public boolean prePop() { return ! isEmpty(); } public boolean preTop() { return ! isEmpty(); } } //--------------------