SS 2002 | Dr. Hannes Federrath |
Übung 4 | Natalie Ardet |
Abgabe bis zum Do. 30.05.02 |
Die Lösung der Aufgaben und die Abgabe der Lösungen erfolgt in Zweiergruppen!
Hinweis: Benutze die Ressourcen der ALP2 Webseite.
Welche Vor- und Nachteile hat die Speicherung von Datenelementen mit einer Reihung (=array) gegenüber der mit einer Liste?
public class StringStack { // ... (add needed fields here) /** * Constructor. * Parameter n defines the stack's capacity, the max No of Objects which can * stored in this stack. */ public StringStack(int capacity) { // ... } /** * Removes the top element from this stack and returns it. * */ public String pop() { // ... } /** * Puts the given parameter on top of this stack. * */ public void push(String element) { // ... }
/** * Returns true if the stack is full i.e. the number of elements in the stack* has reached the maximum capacity of the stack. Otherwise returns false. * */ public boolean isFull() { // ... }
/** * Returns true if the stack contains no element, otherwise returns false. * */ public boolean isEmpty() { // ... } }
Beim Stapel spricht man auch von einer LIFO für Last In First Out, da (analog zum Tellerstapel) das nächste aus der Datenstruktur zu entfernende Element immer das zuletzt eingefügte ist. Im Gegensatz dazu wird bei einer Warteschlange oder Queue (FIFO für First In First Out) immer das älteste Element ausgegeben/entfernt. Die Implementierung einer Queue kann nun ebenfalls auf einer Liste oder einer Reihung aufsetzten.
public class Queue { // ... (add needed fields here) /** * Constructor. * Parameter n defines the queue's capacity, the max No of Objects which can * stored in this queue. */ public Queue(int capacity) { // ... } /** * Removes the first element from this queue and returns it. */ public Object pop(){ // ... } /** * Puts the given parameter at the end of this queue. * */ public void push(Object object) { // ... }
/** * Returns true if the queue is full i.e. the number of elements in the queue * has reached the maximum capacity of the queue. Otherwise returns false. * */ public boolean isFull() { // ... }
/** * Returns true if the queue contains no element, otherwise returns false. * */ public boolean isEmpty() { // ... } }
03.06.2002