使用python实现的树遍历,包括宽度优先和深度优先 ef dfs(): tree = { 'A': ['B', 'C'], 'B': ['D', 'E'], 'C': ['F', 'G'], 'D': ['H', 'I'], 'E': [], 'F': [], 'G': [], 'H': [], 'I': [] } leaf = [] to_crawl = deque(['A']) while to_crawl: current = to_crawl.popleft() print curre