Package dsa.lab02.base
Interface DynamicSequence<Item>
- Type Parameters:
Item- the item type
- All Superinterfaces:
Container<Item>,Iterable<Item>,StaticSequence<Item>
- All Known Subinterfaces:
LinkedList<Item>
- All Known Implementing Classes:
CircularDynamicArray,CircularDynamicArray,DoublyLinkedList,DoublyLinkedList,DynamicArray,DynamicArray,SinglyLinkedList,SinglyLinkedList,StaticArray,StaticArray
A dynamic sequence.
A sequence that can have items inserted into or removed from it; these operations change (increment or decrement) the size of the dynamic sequence.
-
Nested Class Summary
Nested classes/interfaces inherited from interface dsa.lab02.base.StaticSequence
StaticSequence.ForwardIterator<Item>, StaticSequence.ReverseIterator<Item> -
Method Summary
Modifier and TypeMethodDescriptionvoidInsert the given item at the given index.default voidinsertFirst(Item item) Insert the given item as the first.default voidinsertLast(Item item) Insert the given item as the last.remove(int index) Remove and return the item at the given index.default ItemRemove and return the first item.default ItemRemove and return the last item.Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
insert
Insert 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.
- Parameters:
index- the indexitem- the new item- Throws:
IndexOutOfBoundsException- ifindex< 0 orindex>n(wherenis the size)
-
remove
Remove 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.
- Parameters:
index- the index- Returns:
- the item that was at that index
- Throws:
IndexOutOfBoundsException- ifindex< 0 orindex>=n(wherenis the size)
-
insertFirst
Insert the given item as the first.Increments the size, as well as the indices of all the other items.
- Parameters:
item- the new item that should now be at index 0
-
insertLast
Insert the given item as the last.Increments the size.
- Parameters:
item- the new item that should now be at indexn(wherenis the old size)
-
removeFirst
Remove and return the first item.Decrements the size, as well as the indices of all the other items.
- Returns:
- the old item that was at index 0
- Throws:
NoSuchElementException- if there's no first item to remove (i.e. this is empty)
-
removeLast
Remove and return the last item.Decrements the size.
- Returns:
- the old item that was at index
n-1 (wherenis the old size) - Throws:
NoSuchElementException- if there's no last item to remove (i.e. this is empty)
-