package de.fhw.bi.stack;import de.fhw.bi.adt.CharStack;public class ListCharStack implements CharStack { // ------------------------------------- // ------------ ListElement ------------ // ------------------------------------- public class ListElement { // ------------ FELDER ------------ private char _data; private ListElement _next; private ListElement _previous; // ------------ ACCESSOREN ------------ public ListElement getNext() { return _next; } public ListElement getPrevious() { return _previous; } public char getData() { return _data; } // ------------ MUTATOREN ------------ public void setNext(ListElement anElement) { _next = anElement; } public void setPrevious(ListElement anElement) { _previous = anElement; } public void setData(char aData) { _data = aData; } } // ------------------------------------- // ------------ ListCharStack ---------- // ------------------------------------- // ------------ FELDER ------------ private ListElement _last; private ListElement _first; private int _size; // ------------ CONSTRUKTOR ------------ public ListCharStack() { _first = null; _last = null; _size = 0; } // ------------ ACCESSOREN ------------ /** * @see de.fhw.bi.adt.charStack#isEmpty() */ public boolean isEmpty() { if (_size == 0) return true; else return false; } /** * @see de.fhw.bi.adt.charStack#top() */ public char top() { if (_last != null) return _last.getData(); else return (' '); } // ------------ MUTATOREN ------------ /** * @see de.fhw.bi.adt.charStack#push(char) */ public void push(char c) { ListElement neu = new ListElement(); neu.setData(c); if (_last != null) { neu.setNext(null); neu.setPrevious(_last); _last.setNext(neu); _last = neu; } else { _last = neu; _first = neu; } _size++; } /** * @see de.fhw.bi.adt.charStack#push(char) */ public void pop() { ListElement temp = new ListElement(); if (_size >= 3) { _last.getPrevious().setPrevious( _last.getPrevious().getPrevious()); _last.getPrevious().setNext(null); _last = _last.getPrevious(); } else if (_size >= 2) { _last = _first; //_last.setNext(null); } else { _last = null; _first = null; } _size--; } public Object clone() throws CloneNotSupportedException { ListCharStack kopie = this; ListCharStack temp = new ListCharStack(); while (kopie._size>0) { } return temp; } public boolean equals(ListCharStack list) { ListCharStack kopie = this; boolean test = true; if (this._size != list._size) return false; while (kopie._size > 0) { if (kopie.top() != list.top()) { test = false; break; } kopie.pop(); list.pop(); } return test; } }