因此,我有:
class Tree(object):
def__init__(self):
self.right = None
self.left = None
self.val = None
I populate the tree with stuff in my code.
我愿写一下表格的功能。
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))
下面只是一种功能,即渗透到树中的下一个 no子上,扩散是一种可再生功能,其形式如下:
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))
...
...
我的“主要”
node = Tree()
newEquation = []
pos = 0
pos, newTree = buildTree(node, equation, pos)
newEquation = diff(newTree, newEquation, variable)
newEquation = .join(newEquation)
print newEquation
我将如何写上<代码>mult()功能,接受树冠作为参数,然后把<代码>diff(再次运作?