MCPcopy Index your code
hub / github.com/Jack-Lee-Hiter/AlgorithmsByPython / printexp

Function printexp

ParseTree.py:78–84  ·  view source on GitHub ↗
(tree)

Source from the content-addressed store, hash-verified

76
77# 因为中序遍历会丢失括号信息, 因此尝试构造一个函数回复解析表达式
78def printexp(tree):
79 sVal = ''
80 if tree:
81 sVal = '(' + printexp(tree.getLeftChild())
82 sVal = sVal + str(tree.getRootVal())
83 sVal = sVal + printexp(tree.getRightChild()) + ')'
84 return sVal
85
86
87pt = buildParseTree("( ( 10 + 5 ) * 3 )")

Callers 1

ParseTree.pyFile · 0.85

Calls 3

getLeftChildMethod · 0.80
getRootValMethod · 0.80
getRightChildMethod · 0.80

Tested by

no test coverage detected