How can I convert the following recursive code to a non recursive code?
In particular, I am looking at the last 2 line of code. I hope I am able to get help or clue as I am currently totally clueless.
def newNode(data):
return node(data)
# Function to print Leaf Nodes at
# a given level
def PrintLeafNodes(root, level):
if (root == None):
return
if (level == 1):
if (root.left == None and
root.right == None):
print(root.data, end = " ")
elif (level > 1):
PrintLeafNodes(root.left, level - 1) #convert from recursive to non recursive
PrintLeafNodes(root.right, level - 1) #convert from recursive to non recursive