So I have the following:
class Tree(object):
def__init__(self):
self.right = None
self.left = None
self.val = None
I populate the tree with stuff in my code.
I'd like to write a function of the form
def mult(newVal, node)
newVal = diff(node.left, newVal, var)
newVal.append('*')
newval.append(next(node.right))
newVal.append('+')
newVal = diff(node.left, newVal, var)
newVal.append('*')
newVal.append(next(node.left))
Where next is simply a function that traverses to the next node in the tree, and diff is a recursive function of the following form:
def diff(node, newVal, var):
...
...
elif(node.val == '*'):
newVal = diff(node.left, newVal, var)
newVal.append('*')
newval.append(next(node.right))
newVal.append('+')
newVal = diff(node.left, newVal, var)
newVal.append('*')
newVal.append(next(node.left))
...
...
and my "main" is
node = Tree()
newEquation = []
pos = 0
pos, newTree = buildTree(node, equation, pos)
newEquation = diff(newTree, newEquation, variable)
newEquation = ''.join(newEquation)
print newEquation
How would I write the def mult() function to accept a tree node as a parameter, and then call the diff() function again?