Skip to main content

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

MethodDescription
add_frontAdds an element to the front of the linkedList
add_backAdds an element to the back of the linkedList
add_at_indexAdds an element at a specified index of the linkedlist
remove_frontRemove an element from the front of the linked list
remove_backRemove an element from the back of the linked list
remove_at_indexRemove an element at a specified index of the linkedlist
updateUpdate the value of an element at a specified index
getReturns the element at a specified index
mapMaps the current LinkedList to a function. Returns a new LinkedList
filterFilter the Linkedlist based on a function. Returns a new Linkedlist
to_listConverts 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