📜  python广度优先搜索——Python代码示例

📅  最后修改于: 2022-03-11 14:47:15.901000             🧑  作者: Mango

代码示例1
# tree level-by-level traversal. O(n) time/space
def breadthFirstSearch(root):
    q = [root]

    while q:
        current = q.pop(0)
        print(current)
        if current.left is not None: q.append(current.left)
        if current.right is not None: q.append(current.right)