random_simple_loopfree_graph
.
The graph generated may have a cycle, so you can put the graph generation
into a loop until an acyclic graph is generated ...
do { random_simple_loopfree_graph(MyGraph,NumberOfNodes,NumberOfEdges); } while (!Is_Acyclic(MyGraph));
struct
to record both its in-degree and
(for nodes with in-degree 0) the next node with in-degree 0 ...typedef struct { node NextNode; int InDegree; } node_degree;Then use a node array of
node_degree
...node_array<node_degree> Predecessors(MyGraph);
geoff@duck:~/c++> TO 5 5 Creating random graph with 5 nodes and 5 edges ... [0] : [0]---->[4][0]---->[3] [1] : [2] : [2]---->[4][2]---->[1][2]---->[0] [3] : [4] : [2][0][3][4][1]There's an executable version
~geoff/c++/TO
available on
duck
for you to experiment with.