Skip to main content

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

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