Created
November 4, 2019 16:07
-
-
Save imedadel/c4fed69954991de73c930e5a0d7b63a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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