You are viewing a single comment's thread. Return to all comments →
Python 3:
def insertNodeAtPosition(llist, data, position):
nd = SinglyLinkedListNode(data) if position == 0: nd.next = llist return nd else: prev = llist nx = llist.next while position > 1: position -= 1 prev = prev.next nx = nx.next prev.next = nd nd.next = nx return llist
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 →
Python 3:
def insertNodeAtPosition(llist, data, position):