Skip to main content

LinkedList.update

Update the value of an item at a specified index

Usage

update(index: int, new_item:Any)

Parameters:
      index : int
            The index of the item to be updated.
      new_item : element
            The new item to be inserted into the LinkedList.

Returns:
      LinkedList
            Returns the same Linked List with the updated item.

Example

from jellybeans.structures import LinkedListLL1 = LinkedList([10, 3, 7, 29])LL1.update(1, 11).update(2, 12)print(LL1) # 10 => 11 => 12 => 29LL2 = LinkedList([5, 6, 7])LL2.update(1, 15)print(LL2) # 5 => 15 => 7