![]() |
AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
|
Implementation of a doubly linked list. More...
Classes | |
class | BackwardIterator |
Backward iterator. More... | |
class | Backwards |
Utility class to obtain a BackwardIterator . More... | |
class | ForwardIterator |
Forward iterator. More... | |
class | Node |
Public Member Functions | |
DList () | |
create empty list More... | |
int | size () |
determine number of entries [O(n)] More... | |
boolean | empty () |
determine if list is empty [O(1)] More... | |
T | front () |
retrieve first entry (must exist) [O(1)] More... | |
T | back () |
retrieve last entry (must exist) [O(1)] More... | |
T | at (int i) |
retrieve i-th entry [O(n)] More... | |
void | push_front (T obj) |
insert entry at front of list [O(1)] More... | |
void | push_back (T obj) |
append entry obj at end of list [O(1)] More... | |
void | insert (int i, T obj) |
insert new entry obj at position i [O(n)] More... | |
void | pop_front () |
erase first entry (must exist) [O(1)] More... | |
void | pop_back () |
erase last entry (must exist) [O(1)] More... | |
void | erase (int i) |
erase entry at position i [O(n)] More... | |
void | clear () |
Erase all entries. More... | |
ForwardIterator | iterator () |
get forward iterator More... | |
BackwardIterator | reverse_iterator () |
get backward iterator iterator More... | |
Backwards | backwards () |
Get instance that provides a BackwardIterator . More... | |
void | insert_after (ForwardIterator i, T object) |
insert entry after iterator position More... | |
void | insert_before (ForwardIterator i, T object) |
insert entry before iterator position More... | |
String | toString () |
String | toDot () |
Get dot representation. More... | |
String | toDot () |
Get dot representation. More... | |
Protected Attributes | |
Node | head_ = null |
Node | tail_ = null |
Implementation of a doubly linked list.
The implementation is inspired by std::list of the C++ standard library.
DList does not define a bidirectional ListIterator
.
DList defines ForwardIterator
(standard) iterator
and BackwardIterator
reverse_iterator
.
Iterators remain valid after insertion.
Iterators remain valid after removing entries, unless the current entry (that an iterator "points to") is removed.
There are methods to insert entries before and after an interator.
The utility class Backwards
allows for using loops like
for (T item : dlist.backwards()) { ... }
Implementation note: Methods that access (or erase) entries generally assume that entries exist (!empty
). A java.lang.IndexOutOfBoundsException is thrown otherwise (see utility method check()
).
Definition at line 46 of file DList.java.
T aud.DList< T >.at | ( | int | i | ) |
retrieve i-th entry [O(n)]
IndexOutOfBoundsException |
Definition at line 131 of file DList.java.
References aud.DList< T >.head_.
Referenced by aud.test.DListTest.testEntries(), aud.test.DListTest.testInvalid_at(), and aud.test.DListTest.testList().
T aud.DList< T >.back | ( | ) |
retrieve last entry (must exist) [O(1)]
Definition at line 122 of file DList.java.
Referenced by aud.test.DListTest.testInvalid_back(), and aud.test.DListTest.testList().
Get instance that provides a BackwardIterator
.
You cannot use reverse_iterator
directly in a for-each loop, because this loop assumes the iterator is provided via the Iterable
interface, which is already implemented (in forward direction).
The utility class Backwards
implements Iterable
and provides a BackwardIterator
. Then in a for-each loop, instead of list
just write list.backwards
.
Definition at line 346 of file DList.java.
Referenced by aud.test.DListTest.testIterators().
void aud.DList< T >.clear | ( | ) |
Erase all entries.
[O(1)]
Definition at line 245 of file DList.java.
References aud.DList< T >.head_, and aud.DList< T >.tail_.
boolean aud.DList< T >.empty | ( | ) |
determine if list is empty [O(1)]
Definition at line 92 of file DList.java.
References aud.DList< T >.head_, and aud.DList< T >.tail_.
Referenced by aud.test.DListTest.testCtor(), and aud.test.DListTest.testList().
void aud.DList< T >.erase | ( | int | i | ) |
erase entry at position i [O(n)]
Definition at line 224 of file DList.java.
References aud.DList< T >.head_.
Referenced by aud.test.DListTest.testInvalid_erase(), and aud.test.DListTest.testList().
T aud.DList< T >.front | ( | ) |
retrieve first entry (must exist) [O(1)]
Definition at line 113 of file DList.java.
Referenced by aud.test.DListTest.testEntries(), aud.test.DListTest.testInvalid_front(), and aud.test.DListTest.testList().
void aud.DList< T >.insert | ( | int | i, |
T | obj | ||
) |
insert new entry obj at position i [O(n)]
Definition at line 185 of file DList.java.
Referenced by aud.util.SingleStepperDemo.main(), and aud.test.DListTest.testList().
void aud.DList< T >.insert_after | ( | ForwardIterator | i, |
T | object | ||
) |
insert entry after iterator position
Definition at line 351 of file DList.java.
void aud.DList< T >.insert_before | ( | ForwardIterator | i, |
T | object | ||
) |
insert entry before iterator position
Definition at line 356 of file DList.java.
Referenced by aud.test.DListTest.testIterators().
ForwardIterator aud.DList< T >.iterator | ( | ) |
get forward iterator
Definition at line 303 of file DList.java.
References aud.DList< T >.head_.
Referenced by aud.test.DListTest.testIterators().
void aud.DList< T >.pop_back | ( | ) |
erase last entry (must exist) [O(1)]
Definition at line 212 of file DList.java.
References aud.DList< T >.tail_.
Referenced by aud.test.DListTest.testInvalid_pop_back(), and aud.test.DListTest.testList().
void aud.DList< T >.pop_front | ( | ) |
erase first entry (must exist) [O(1)]
Definition at line 200 of file DList.java.
References aud.DList< T >.head_.
Referenced by aud.test.DListTest.testInvalid_pop_front(), and aud.test.DListTest.testList().
void aud.DList< T >.push_back | ( | T | obj | ) |
append entry obj at end of list [O(1)]
Definition at line 154 of file DList.java.
References aud.DList< T >.head_, and aud.DList< T >.tail_.
Referenced by aud.util.SingleStepperDemo.main(), aud.test.DListTest.testIterators(), and aud.test.DListTest.testList().
void aud.DList< T >.push_front | ( | T | obj | ) |
insert entry at front of list [O(1)]
Definition at line 142 of file DList.java.
References aud.DList< T >.head_, and aud.DList< T >.tail_.
Referenced by aud.util.SingleStepperDemo.main(), aud.test.DListTest.testEntries(), aud.test.DListTest.testInvalid_at(), aud.test.DListTest.testInvalid_erase(), aud.test.DListTest.testList(), and aud.test.DListTest.testSize().
BackwardIterator aud.DList< T >.reverse_iterator | ( | ) |
get backward iterator iterator
Definition at line 307 of file DList.java.
References aud.DList< T >.tail_.
Referenced by aud.test.DListTest.testIterators().
int aud.DList< T >.size | ( | ) |
determine number of entries [O(n)]
Definition at line 79 of file DList.java.
References aud.DList< T >.head_.
Referenced by aud.test.DListTest.testEntries(), aud.test.DListTest.testList(), and aud.test.DListTest.testSize().
String aud.DList< T >.toDot | ( | ) |
Get dot representation.
Implements aud.util.Graphvizable.
Definition at line 380 of file DList.java.
References aud.DList< T >.head_.
String aud.DList< T >.toString | ( | ) |
Definition at line 366 of file DList.java.
References aud.DList< T >.head_.
Definition at line 59 of file DList.java.
Referenced by aud.DList< T >.at(), aud.DList< T >.clear(), aud.DList< T >.empty(), aud.DList< T >.erase(), aud.DList< T >.iterator(), aud.DList< T >.pop_front(), aud.DList< T >.push_back(), aud.DList< T >.push_front(), aud.DList< T >.size(), aud.DList< T >.toDot(), and aud.DList< T >.toString().
Definition at line 60 of file DList.java.
Referenced by aud.DList< T >.clear(), aud.DList< T >.empty(), aud.DList< T >.pop_back(), aud.DList< T >.push_back(), aud.DList< T >.push_front(), and aud.DList< T >.reverse_iterator().