Skip to main content

TailedLinkedList

Instantiate a TailedLinkedList with 0 items, 1 item, or a collection of items.

Usage

TailedLinkedList(item:Any = None)

Parameters:
      item : None or element or List or Tuple
            Default is None, where an empty TailedLinkedList is created. When item is not a list or tuple, a TailedLinkedList with one element is created.             Otherwise, a TailedLinkedList of multiple elements is created.

Methods

MethodDescription
add_frontAdds an element to the front of the TailedlinkedList
add_backAdds an element to the back of the TailedlinkedList
add_at_indexAdds an element at a specified index of the Tailedlinkedlist
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 Tailedlinkedlist
updateUpdate the value of an element at a specified index
getReturns the element at a specified index
mapMaps the current TailedLinkedList to a function. Returns a new TailedLinkedList
filterFilter the TailedLinkedlist based on a function. Returns a new TailedLinkedlist
to_listConverts the TailedLinkedList to a list

Example

from jellybeans.structures import TailedLinkedListlst = [9, 19, 1, 17, 6, 20, 4, 13, 15, 3]LL1 = TailedLinkedList()LL2 = TailedLinkedList(3)LL3 = TailedLinkedList(lst)print(LL1) # []print(LL2) # 3print(LL3) # 9 => 19 => 1 => 17 => 6 => 20 => 4 => 13 => 15 => 3