Get Node Value:

#Body
"""
 Get Node data of the Nth Node from the end.
 head could be None as well for empty 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 node data of the linked list in the below method.
"""

def GetNode(head, position):
    current=head
    count = 0
    while current!=None:
        count+=1
        current = current.next

    new_count = count-position
    count_a = 1
    while count_a != new_count:
        head = head.next
        count_a+=1

    return head.data

results matching ""

    No results matching ""