Package dsa.lab02.solutions
Class SinglyLinkedList<Item>
java.lang.Object
dsa.lab02.solutions.SinglyLinkedList<Item>
- Type Parameters:
- Item- the item type
- All Implemented Interfaces:
- Container<Item>,- DynamicSequence<Item>,- LinkedList<Item>,- StaticSequence<Item>,- Iterable<Item>
A singly-linked list.
 
Nodes are only directly linked to their successors. Holds references to both the first and last nodes (if non-empty).
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classA node in a singly-linked list.Nested classes/interfaces inherited from interface dsa.lab02.base.LinkedListLinkedList.ForwardNodeIterator<Item>, LinkedList.NodeIterator<Item>, LinkedList.ReverseNodeIterator<Item>Nested classes/interfaces inherited from interface dsa.lab02.base.StaticSequenceStaticSequence.ForwardIterator<Item>, StaticSequence.ReverseIterator<Item>
- 
Constructor SummaryConstructorsConstructorDescriptionConstruct an empty singly-linked list.SinglyLinkedList(Item... items) Construct a singly-linked list containing the given items.SinglyLinkedList(Iterable<Item> items) Construct a singly-linked list containing the given items.
- 
Method SummaryMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface dsa.lab02.base.DynamicSequenceinsertFirst, insertLast, removeFirst, removeLastMethods inherited from interface java.lang.IterableforEach, spliteratorMethods inherited from interface dsa.lab02.base.LinkedListfirstNode, get, items, lastNode, nodes, reversed, reversedNodes, set
- 
Constructor Details- 
SinglyLinkedListpublic SinglyLinkedList()Construct an empty singly-linked list.
- 
SinglyLinkedListConstruct a singly-linked list containing the given items.- Parameters:
- items- the items
 
- 
SinglyLinkedListConstruct a singly-linked list containing the given items.- Parameters:
- items- the items
 
 
- 
- 
Method Details- 
sizepublic int size()Description copied from interface:ContainerGet the number of contained items.
- 
nodeDescription copied from interface:LinkedListGet the node at the given index.- Specified by:
- nodein interface- LinkedList<Item>
- Parameters:
- index- the index
- Returns:
- the node that is at that index
- Throws:
- IndexOutOfBoundsException- if- index< 0 or- index>=- n(where- nis the size)
 
- 
insertDescription copied from interface:DynamicSequenceInsert the given item at the given index.Increments the size, as well as the indices of all items that had the same index or higher. - Specified by:
- insertin interface- DynamicSequence<Item>
- Parameters:
- index- the index
- item- the new item
- Throws:
- IndexOutOfBoundsException- if- index< 0 or- index>- n(where- nis the size)
 
- 
removeDescription copied from interface:DynamicSequenceRemove and return the item at the given index.Decrements the size, as well as the indices of all items that had the same index or higher. - Specified by:
- removein interface- DynamicSequence<Item>
- Parameters:
- index- the index
- Returns:
- the item that was at that index
- Throws:
- IndexOutOfBoundsException- if- index< 0 or- index>=- n(where- nis the size)
 
 
-