DoublyLinkedList
Instantiate a DoublyLinkedList with 0 items, 1 item, or a collection of items.
Usage
DoublyLinkedList(item:Any = None)
Parameters:
item : None or element or List or Tuple
Default is None, where an empty DoublyLinkedList is created. When item is not a list or tuple, a DoublyLinkedList with one element is created.
Otherwise, a DoublyLinkedList of multiple elements is created.
Methods
Method | Description |
---|---|
add_front | Adds an element to the front of the DoublyLinkedList |
add_back | Adds an element to the back of the DoublyLinkedList |
add_at_index | Adds an element at a specified index of the DoublyLinkedList |
remove_front | Remove an element from the front of the linked list |
remove_back | Remove an element from the back of the linked list |
remove_at_index | Remove an element at a specified index of the DoublyLinkedList |
update | Update the value of an element at a specified index |
get | Returns the element at a specified index |
map | Maps the current DoublyLinkedList to a function. Returns a new DoublyLinkedList |
filter | Filter the DoublyLinkedList based on a function. Returns a new DoublyLinkedList |
to_list | Converts the DoublyLinkedList to a list |
invert | Reverses the Doubly Linked List |
Example
from jellybeans.structures import DoublyLinkedListlst = [9, 19, 1, 17, 6, 20, 4, 13, 15, 3]LL1 = DoublyLinkedList()LL2 = DoublyLinkedList(3)LL3 = DoublyLinkedList(lst)print(LL1) # []print(LL2) # 3print(LL3) # 9 => 19 => 1 => 17 => 6 => 20 => 4 => 13 => 15 => 3