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