BinaryTree t ← 生成二叉树
# 从 s 开始层序遍历二叉树 t 的节点
levelorder(s):
Queue que
que.push(s)
time ← 1
while not que.empty():
u ← que.dequeue()
L[u] ← time++
if t.nodes[u].left ≠ NIL:
que.push(t.nodes[u].left)
if t.nodes[u].right ≠ NIL:
que.push(t.nodes[u].right)
# 从二叉树的根节点开始访问
levelorder(t.root)