def connected_cuthill_mckee_ordering(G, start=None):
    # the cuthill mckee algorithm for connected graphs
    if start is None:
        (_, start) = find_pseudo_peripheral_node_pair(G)
    yield start
    visited = set([start])
    stack = [(start, iter(G[start]))]
    while stack:
        parent,children = stack[0]
        if parent not in visited:
            yield parent
        try:
            child = next(children)
            if child not in visited:
                yield child
                visited.add(child)
                # add children to stack, sorted by degree (lowest first)
                nd = sorted(G.degree(G[child]).items(), key=itemgetter(1))
                children = (n for n,d in nd)
                stack.append((child,children))
        except __HOLE__:
            stack.pop(0)
dataset/ETHPy150Open gkno/gkno_launcher/src/networkx/utils/rcm.py/connected_cuthill_mckee_ordering