def topological_ordering(nodes):
    ordered_nodes = [node for node in nodes if len(node.incoming_nodes) == 0]

    index = 0
    while index < len(ordered_nodes):
        node = ordered_nodes[index]
        for nextnode in node.outgoing_nodes:
            if all(n in ordered_nodes for n in nextnode.incoming_nodes) and nextnode not in ordered_nodes:
                ordered_nodes.append(nextnode)
        index += 1

    return ordered_nodes