Insert a node at a specific position in a linked list

  • + 0 comments

    def insertNodeAtPosition(llist, data, position): # Write your code here if llist is None: llist = SinglyLinkedList() llist.data = data else: current = llist for i in range(1, position): current = current.next

        new_next = SinglyLinkedList()
        new_next.data = data
        new_next.next = current.next
        current.next = new_next
    return llist