Doubly Linked List¶
| Spice | |
|---|---|
DoublyLinkedList<T> struct¶
A doubly linked list is a common, dynamically resizable data structure to store uniform data in order. It is characterized by the pointer for every item, pointing to the next one and the pointer, pointing to the previous one.
Time complexity:
Insert at front/back: O(1)
Insert at index: O(n)
Delete at front/back: O(1)
Delete at index: O(n)
Search: O(n)
Beware that each add operation allocates memory and every remove operation frees memory.
Methods¶
pushBack¶
| Spice | |
|---|---|
Pushes a new item to the back of the list
Parameters
| Name | Type | Description |
|---|---|---|
value |
const T& |
Value to push |
pushFront¶
| Spice | |
|---|---|
Pushes a new item to the front of the list
Parameters
| Name | Type | Description |
|---|---|---|
value |
const T& |
Value to push |
insertAt¶
| Spice | |
|---|---|
Inserts a new item at the given index
Parameters
| Name | Type | Description |
|---|---|---|
idx |
unsigned long |
Index to insert the new item |
value |
const T& |
Value to insert |
remove¶
| Spice | |
|---|---|
Removes the first occurrence of the given value
Parameters
| Name | Type | Description |
|---|---|---|
valueToRemove |
const T& |
Value to remove |
removeAt¶
| Spice | |
|---|---|
Removes the item at the given index
Parameters
| Name | Type | Description |
|---|---|---|
idx |
unsigned long |
Index to remove |
removeAt¶
| Spice | |
|---|---|
Removes the item at the given index
Parameters
| Name | Type | Description |
|---|---|---|
idx |
unsigned int |
Index to remove |
removeFront¶
| Spice | |
|---|---|
Removes the first item of the list
removeBack¶
| Spice | |
|---|---|
Removes the last item of the list
getSize¶
| Spice | |
|---|---|
Returns the size of the list
Returns: unsigned long — Size of the list
isEmpty¶
| Spice | |
|---|---|
Returns if the list is empty
Returns: bool — true if the list is empty, false otherwise
get¶
| Spice | |
|---|---|
Returns the item at the given index
Parameters
| Name | Type | Description |
|---|---|---|
idx |
unsigned long |
Index to access |
Returns: T& — Reference to the item
get¶
| Spice | |
|---|---|
Returns the item at the given index
Parameters
| Name | Type | Description |
|---|---|---|
idx |
unsigned int |
Index to access |
Returns: T& — Reference to the item
getFront¶
| Spice | |
|---|---|
Returns the first item of the list
Returns: T& — Reference to the first item
getBack¶
| Spice | |
|---|---|
Returns the last item of the list
Returns: T& — Reference to the last item