i tried to program a iterator that returns the data in a linked list in a reversed way , from the last Node to the head node.
but for some reason only the first value us returned , the one that in the first recursion level.
=============code ===========
class Node:
def __init__(self ,data ,next=None):
self.data = data
self.next = next
def foo(head):
if head.next is None:
yield head.data
else:
foo(head.next)
yield head.data
=============================
head = Node('A',Node("B", Node("C")))
for x in foo(head):
print(x)
======== result==========
A
========should be ========
A B C