Q80226 - 2026编程挑战赛Python提高组26
统计题目( 单选题 )
下列BST的中序遍历结果为:
class Node:
def __init__(self, val):
self.val = val
self.left = None
self.right = None
def insert(root, val):
if root is None:
return Node(val)
if val < root.val:
root.left = insert(root.left, val)
else:
root.right = insert(root.right, val)
return root
def inorder(root):
if root:
inorder(root.left)
print(root.val, end=' ')
inorder(root.right)
nums = [5, 3, 7, 2, 4, 6, 8]
root = None
for n in nums:
root = insert(root, n)
inorder(root)

关注我们