Package dsa.lab02.base
Interface LinkedList<Item>
- Type Parameters:
Item
- the item type
- All Superinterfaces:
Container<Item>
,DynamicSequence<Item>
,Iterable<Item>
,StaticSequence<Item>
- All Known Implementing Classes:
DoublyLinkedList
,DoublyLinkedList
,SinglyLinkedList
,SinglyLinkedList
A linked list.
A dynamic sequence implemented using linked nodes,
with O(n
) iteration in at least one direction
(first-to-last / last-to-first) (where n
is the size)
and O(1) insertion/removal at at least one end (first/last)
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
A forward iterator over the nodes in a linked list.static class
An iterator over the nodes in a linked list.static class
A reverse iterator over the nodes in a linked list.Nested classes/interfaces inherited from interface dsa.lab02.base.StaticSequence
StaticSequence.ForwardIterator<Item>, StaticSequence.ReverseIterator<Item>
-
Method Summary
Modifier and TypeMethodDescriptiondefault LinkedNode
<Item> Get the first node, ornull
if empty.default Item
get
(int index) Get the item at the given index.items()
Get a forward iterable that yields each item once.default LinkedNode
<Item> lastNode()
Get the last node, ornull
if empty.node
(int index) Get the node at the given index.default Iterable
<LinkedNode<Item>> nodes()
Get a forward iterable that yields each node once.reversed()
Get a reverse iterable that yields each item once.default Iterable
<LinkedNode<Item>> Get a reverse iterable that yields each node once.default void
Set the item at the given index.Methods inherited from interface dsa.lab02.base.DynamicSequence
insert, insertFirst, insertLast, remove, removeFirst, removeLast
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
node
Get the node at the given index.- Parameters:
index
- the index- Returns:
- the node that is at that index
- Throws:
IndexOutOfBoundsException
- ifindex
< 0 orindex
>=n
(wheren
is the size)
-
firstNode
Get the first node, ornull
if empty.- Returns:
- the node at index 0
-
lastNode
Get the last node, ornull
if empty.- Returns:
- the node at index
n
-1 (wheren
is the size)
-
get
Description copied from interface:StaticSequence
Get the item at the given index.- Specified by:
get
in interfaceStaticSequence<Item>
- Parameters:
index
- the index- Returns:
- the item that is at that index
- Throws:
IndexOutOfBoundsException
- ifindex
< 0 orindex
>=n
(wheren
is the size)
-
set
Description copied from interface:StaticSequence
Set the item at the given index.Replaces whatever item was there before.
- Specified by:
set
in interfaceStaticSequence<Item>
- Parameters:
index
- the indexitem
- the new item that should now be at that index- Throws:
IndexOutOfBoundsException
- ifindex
< 0 orindex
>=n
(wheren
is the size)
-
nodes
Get a forward iterable that yields each node once.The nodes are iterated over in first-to-last order (by index).
- Returns:
- an iterable over the nodes
-
reversedNodes
Get a reverse iterable that yields each node once.The nodes are iterated over in last-to-first order (by index).
- Returns:
- an iterable over the nodes
-
items
Description copied from interface:StaticSequence
Get a forward iterable that yields each item once.The items are iterated over in first-to-last order (by index).
-
reversed
Description copied from interface:StaticSequence
Get a reverse iterable that yields each item once.The items are iterated over in last-to-first order (by index).
- Specified by:
reversed
in interfaceStaticSequence<Item>
- Returns:
- an iterable over the items
-