Created
April 18, 2017 08:23
-
-
Save DeviaVir/5a251625311d8f531e805491b26f11a8 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
""" | |
Delete Node at a given position in a linked list | |
Node is defined as | |
class Node(object): | |
def __init__(self, data=None, next_node=None): | |
self.data = data | |
self.next = next_node | |
return back the head of the linked list in the below method. | |
""" | |
def Delete(head, position): | |
if not head: | |
return head | |
if position == 0: | |
t = head.next | |
del head | |
return t | |
position -= 1 | |
head.next = Delete(head.next, position) | |
return head | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment