# 以 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)

# 以二元樹的根節點為起點開始走訪
BinaryTree t ← 建立二元樹
levelorder(t.root)