Skip to main content

TailedLinkedList.add_at_index

Adds an item to the Linked List at a specified index

Usage

add_at_index(item:Any, index:int)

Parameters:
      item : element
            The new element that will be added to the Linked List.
      index : int
            The position to place the item at.

Returns:
      TailedLinkedList
            Returns the same Linked List containing the newly added item.

Example

from jellybeans.structures import TailedLinkedListLL1 = TailedLinkedList([10, 3, 7, 29])LL1.add_at_index(28, 2).add_at_index(16, 3).add_at_index(5, 2).add_at_index(78, 1)print(LL1) # 10 => 78 => 3 => 5 => 28 => 16 => 7 => 29LL2 = TailedLinkedList([5, 6, 7])LL2.add_at_index(109, 3)print(LL2) # 5 => 6 => 7 => 109