You are viewing a single comment's thread. Return to all comments →
your logic is unnessessarily complicated. Here's a better python3 version
def InsertNth(head, data, position): if position == 0: node_to_isert = Node(data=data, next_node=head) return node_to_isert node = head for i in range(position-1): node = node.next node_to_isert = Node(data=data, next_node=node.next) node.next = node_to_isert return head
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 →
your logic is unnessessarily complicated. Here's a better python3 version