akellehe
6/15/2015 - 6:55 PM

Gets the descendants using a graph structure, a queue, and a buffer.

Gets the descendants using a graph structure, a queue, and a buffer.

def get_descendants(node):
    unexplored = deque([node])
    while unexplored:
        node = unexplored.popleft()
        yield node
        children = node.children
        for child in children:
            unexplored.append(child)