We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
dummy = SinglyLinkedListNode(data)
curr = llist
i=0
while curr is not None:
i = i+1
next_node = curr.next # save next node
if i == position:
curr.next = dummy #set current nodes next pointer to dummy
dummy.next = next_node #set dummy's next pointer to next_node
curr = next_node #move to the next_node
return llist
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Insert a node at a specific position in a linked list
You are viewing a single comment's thread. Return to all comments →
def insertNodeAtPosition(llist, data, position):