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
Nested ClassesModifier and TypeInterfaceDescriptionstatic classA forward iterator over the nodes in a linked list.static classAn iterator over the nodes in a linked list.static classA 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, ornullif empty.default Itemget(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, ornullif 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 voidSet the item at the given index.Methods inherited from interface dsa.lab02.base.DynamicSequence
insert, insertFirst, insertLast, remove, removeFirst, removeLastMethods 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(wherenis the size)
-
firstNode
Get the first node, ornullif empty.- Returns:
- the node at index 0
-
lastNode
Get the last node, ornullif empty.- Returns:
- the node at index
n-1 (wherenis the size)
-
get
Description copied from interface:StaticSequenceGet the item at the given index.- Specified by:
getin interfaceStaticSequence<Item>- Parameters:
index- the index- Returns:
- the item that is at that index
- Throws:
IndexOutOfBoundsException- ifindex< 0 orindex>=n(wherenis the size)
-
set
Description copied from interface:StaticSequenceSet the item at the given index.Replaces whatever item was there before.
- Specified by:
setin interfaceStaticSequence<Item>- Parameters:
index- the indexitem- the new item that should now be at that index- Throws:
IndexOutOfBoundsException- ifindex< 0 orindex>=n(wherenis 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:StaticSequenceGet 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:StaticSequenceGet a reverse iterable that yields each item once.The items are iterated over in last-to-first order (by index).
- Specified by:
reversedin interfaceStaticSequence<Item>- Returns:
- an iterable over the items
-