Delete a Node:

"""
 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 position == 0:
        return head.next
    curr_node = head
    while position != 1:
        curr_node = curr_node.next
        position -=1
    curr_node.next = (curr_node.next).next
    return head

results matching ""

    No results matching ""