Example Topological OrderingThe following example shows how to compute a topological ordering for a graph using the corresponding basic graph algorithm. The program defines a Remark: It is also possible to use a parameterized
graph instead of a graph as the
first parameter of #include <LEDA/graph/graph.h> #include <LEDA/graph/basic_graph_alg.h> using namespace leda; int main() { graph G; random_graph(G,10,6); node_array<int> ord(G); //node_array for result of TOPSORT bool acyclic=TOPSORT(G,ord); //call TOPSORT for G and ord if (acyclic) { node v; forall_nodes(v,G) { G.print_node(v); std::cout << " " << ord[v] << std::endl; } } else std::cout << "G contains cycles! No topological ordering possible!\n"; return 0; } |
See also:Manual Entries: |