/** * 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 * * ein einfacher stack * abgeleitet aus der abstrakten * Klasse: AbstractStack * * Implementierung aus der SimpleStack Klasse * uebernommen */ //-------------------- public class Stack1 extends AbstractStack { //-------------------- // die Datenfelder fuer die Implementierung private Object[] elems; private int top; //-------------------- // die Konstruktoren public Stack1(int max) { elems = new Object[max]; top = 0; } public Stack1() { this(20); } //-------------------- // die noch fehlenden Funktionsruempfe //-------------------- public boolean isEmpty() { return top == 0; } //-------------------- public Object top() { assert top > 0 : "Stack1.top: empty stack"; return elems[top - 1]; } //-------------------- public void push(Object o) { elems[top++] = o; } //-------------------- public void pop() { assert top > 0 : "Stack1.pop: empty stack"; elems[--top] = null; } } //--------------------