We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def getNode(llist, positionFromTail):
if not llist:
return None
E = []
temp =llist
while temp != None:
E.append(temp.data)
temp = temp.next
# we use positionfromTail -1 bcz we calculate the postion from 1
position = len(E) -1 -positionFromTail
return E[position]
PYTHON using LinkedList
def getNode(llist, positionFromTail):
if not llist:
return None
Get Node Value
You are viewing a single comment's thread. Return to all comments →
PYTHON using list
def getNode(llist, positionFromTail): if not llist: return None
PYTHON using LinkedList
def getNode(llist, positionFromTail): if not llist: return None
to N but when indexing it starts form 0 so for that we have to do -1 position = len(E) -1 - positionFromTail return E[position]