前序遍历
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
def preOrder(self, pRoot, k):
node = pRoot
stack = []
while stack or node: # 停止条件:栈空并且当前节点为空
while node:
print(node.val) # 访问该节点
stack.append(node)
node = node.left
node = stack.pop()
node = node.right # 准备访问右节点
r = TreeNode