Bearbeiten von „StringList:Javakurs“
Zur Navigation springen
Zur Suche springen
Warnung: Du bist nicht angemeldet. Deine IP-Adresse wird bei Bearbeitungen öffentlich sichtbar. Melde dich an oder erstelle ein Benutzerkonto, damit Bearbeitungen deinem Benutzernamen zugeordnet werden.
Die Bearbeitung kann rückgängig gemacht werden. Bitte prüfe den Vergleich unten, um sicherzustellen, dass du dies tun möchtest, und veröffentliche dann unten deine Änderungen, um die Bearbeitung rückgängig zu machen.
Aktuelle Version | Dein Text | ||
Zeile 24: | Zeile 24: | ||
Element succ = null; | Element succ = null; | ||
} | } | ||
/** | /** | ||
* Implements a doubled linked list of strings. | * Implements a doubled linked list of strings. | ||
Zeile 41: | Zeile 42: | ||
private Element last = null; | private Element last = null; | ||
private int count = 0; | private int count = 0; | ||
/** | /** | ||
* Adds a text to the end of the list. | * Adds a text to the end of the list. | ||
Zeile 47: | Zeile 49: | ||
* text to append | * text to append | ||
*/ | */ | ||
void add(final String text) { | |||
final Element element = new Element(); | final Element element = new Element(); | ||
element.text = text; | element.text = text; | ||
Zeile 55: | Zeile 57: | ||
element.pred = this.last; | element.pred = this.last; | ||
this.last.succ = element; | this.last.succ = element; | ||
} | } | ||
this.count++; | this.count++; | ||
} | } | ||
/** | /** | ||
* | * Gets the text of the n-th element of the list. | ||
* | * | ||
* @param index | * @param index | ||
* index of the wanted element | * index of the wanted element | ||
* @return null: wrong index<br> | * @return <code>null</code>: wrong index<br> | ||
* otherwise: the text of the element with index <code>index</code> | * otherwise: the text of the element with index <code>index</code> | ||
*/ | */ | ||
String get(final int index) { | |||
Element element = this.first; | |||
for (int ix = 0; element != null && ix < index - 1; ix++) | |||
element = element.succ; | |||
return element == null ? null : element.text; | |||
} | } | ||
/** | /** | ||
* @return the count | * @return the count | ||
Zeile 78: | Zeile 82: | ||
return this.count; | return this.count; | ||
} | } | ||
/** | /** | ||
* @return the first | * @return the first | ||
Zeile 102: | Zeile 89: | ||
return this.first; | return this.first; | ||
} | } | ||
/** | /** | ||
* @return the last | * @return the last | ||
Zeile 108: | Zeile 96: | ||
return this.last; | return this.last; | ||
} | } | ||
} | } | ||
</pre> | </pre> | ||