Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**************************** BackListe.java *******************************/
- /**
- * Eine BackListe erweitert den ADT Liste um die Methode
- * <tt>public void back();</tt>
- *
- * @version 15.12.2007
- *
- * @author Patrick Fox (pfox@uos.de)
- * @author Dorothee Langfeld (dlangfel@uos.de)
- */
- public class BackListe extends VerweisListe {
- /**
- * Macht das Element _vor_ dem aktuellen zum aktuellen. Wenn der Rueckschritt
- * nicht moeglich war, wir eine ListenException geworfen.
- *
- * @throws ListenException, falls nicht Rueckschritt geklappt hat
- */
- public void back() throws ListenException {
- if (super.empty()) throw new ListenException("Liste ist leer");
- Object hilf = super.elem(); // Aktuelles Element
- int hilfpos = 0; // Position in der Liste
- super.reset(); // Zum Listenanfang
- while (hilf != super.elem()) { // Element gleich hilf?
- hilfpos++; // Position erhoehen
- super.advance(); // Naechstes Element
- }
- if (hilfpos == 0) // Schleife nicht durchlaufen
- throw new ListenException("Liste war auf Startposition");
- super.reset(); // Auf Anfang springen
- for(int i = 0; i <= hilfpos; i++) // Auf vorhergehenden Knoten
- super.advance();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement