code: def sort(self):
          while self.nodes:
              iterated = False
              for node in self.leaf_nodes():
                  iterated = True
                  self.prune_node(node)
                  yield node
              if not iterated:
                  raise CyclicGraphError("Sorting has found a cyclic graph.")