Data Structures, Algorithms, Data Engineering, Data Science, Linked Lists.
insert(self, data, index=None): new_node = Node(data) if index is None or not self.head: # Insert at end or if list is empty self.append(new_node) else: current = self.head count = 0 while current.next and count < index - 1: current = current.next count += 1 new_node.next = current.next