Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save imedadel/c4fed69954991de73c930e5a0d7b63a9 to your computer and use it in GitHub Desktop.
Save imedadel/c4fed69954991de73c930e5a0d7b63a9 to your computer and use it in GitHub Desktop.
def insertNodeAtPosition(head, data, position):
if position == 0:
new_node = SinglyLinkedListNode(data)
new_node.next = head
return new_node
tmp = head
for i in range(position-1):
tmp = tmp.next
new_node = SinglyLinkedListNode(data)
new_node.next = tmp.next
tmp.next = new_node
return head
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment