Package aud
Class DList<T>
java.lang.Object
aud.DList<T>
- All Implemented Interfaces:
Graphvizable
,Iterable<T>
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 DList<T>.ForwardIterator
(standard) iterator()
and
DList<T>.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 DList<T>.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()
).-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
Backward iterator.class
Utility class to obtain aDList<T>.BackwardIterator
.class
Forward iteratorprotected class
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionat
(int i) retrieve i-th entry [O(n)]back()
retrieve last entry (must exist) [O(1)]Get instance that provides aDList<T>.BackwardIterator
.void
clear()
Erase all entries.boolean
empty()
determine if list is empty [O(1)]void
erase
(int i) erase entry at position i [O(n)]front()
retrieve first entry (must exist) [O(1)]void
insert new entry obj at position i [O(n)]void
insert_after
(DList<T>.ForwardIterator i, T object) insert entry after iterator positionvoid
insert_before
(DList<T>.ForwardIterator i, T object) insert entry before iterator positioniterator()
get forward iteratorvoid
pop_back()
erase last entry (must exist) [O(1)]void
erase first entry (must exist) [O(1)]void
append entry obj at end of list [O(1)]void
push_front
(T obj) insert entry at front of list [O(1)]get backward iterator iteratorint
size()
determine number of entries [O(n)]toDot()
Get dot representation.toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
head_
-
tail_
-
-
Constructor Details
-
DList
public DList()create empty list
-
-
Method Details
-
size
public int size()determine number of entries [O(n)] -
empty
public boolean empty()determine if list is empty [O(1)] -
front
retrieve first entry (must exist) [O(1)] -
back
retrieve last entry (must exist) [O(1)] -
at
retrieve i-th entry [O(n)]- Throws:
IndexOutOfBoundsException
-
push_front
insert entry at front of list [O(1)] -
push_back
append entry obj at end of list [O(1)] -
insert
insert new entry obj at position i [O(n)] -
pop_front
public void pop_front()erase first entry (must exist) [O(1)] -
pop_back
public void pop_back()erase last entry (must exist) [O(1)] -
erase
public void erase(int i) erase entry at position i [O(n)] -
clear
public void clear()Erase all entries. [O(1)] -
iterator
get forward iterator -
reverse_iterator
get backward iterator iterator -
backwards
Get instance that provides aDList<T>.BackwardIterator
. You cannot usereverse_iterator()
directly in a for-each loop, because this loop assumes the iterator is provided via theIterable
interface, which is already implemented (in forward direction). The utility classDList<T>.Backwards
implementsIterable
and provides aDList<T>.BackwardIterator
. Then in a for-each loop, instead oflist
just writelist.backwards
. -
insert_after
insert entry after iterator position -
insert_before
insert entry before iterator position -
toString
-
toDot
Description copied from interface:Graphvizable
Get dot representation.- Specified by:
toDot
in interfaceGraphvizable
-