MCPcopy
hub / github.com/Jack-Lee-Hiter/AlgorithmsByPython / preOrder

Method preOrder

Target Offer/递归和非递归实现二叉搜索树的三种遍历.py:14–25  ·  view source on GitHub ↗
(self, root)

Source from the content-addressed store, hash-verified

12class Tranversal:
13 # preorder without recursion
14 def preOrder(self, root):
15 if root == None:
16 return None
17 pNode, treeStack = root, []
18 while pNode or len(treeStack) > 0:
19 while pNode:
20 print(pNode.val)
21 treeStack.append(pNode)
22 pNode = pNode.left
23 if len(treeStack) > 0:
24 pNode = treeStack.pop()
25 pNode = pNode.right
26 # preorder with recursion
27 def preOrderRec(self, root):
28 if root != None:

Callers

nothing calls this directly

Calls 1

popMethod · 0.45

Tested by

no test coverage detected