Topological sorting
Topological order: If there is a forward path from V to W in the figure, V must precede w. The sequence of vertices that satisfy this condition is called a topological order.
The process of obtaining a topological order is the topological ordering
A sequence is obtained after the topology is sorted
Each time we want to output a node without a precursor vertex, that is, a point with no degree of penetration. After the output, set the vertex to 0
AOV (Activity on vertex Network) if there is a reasonable topological order it must be a directed acyclic graph (Directed acyclic graph, DAG)
V must end before the start of v,,,, obvious error,,, so a reasonable topological order cannot exist ring.
voidTopsort () { for(cnt=0; cnt<v;cnt++) {V= a vertex with an input level of 0 not being output;//This step is discussed below. if(Such a v does not exist) {Error ("There is a circuit in the diagram"); Break; } output V, or record the output sequence of V for(V for each pro contact W) Indegree[w]--;//a reduction of V so that the penetration of each of the pro contacts will be reduced by one. }}
The first solution is to iterate over the time complexity to n^2.
The second solution is to put the degree of entry into a different container at any time by turning it into 0. Time complexity is a constant number of levels
The second method uses the queue when the code is as follows
voidTopsort () { for(each vertex on the way V)if(indegree[v]==0) Enqueue[v,q]; while(!IsEmpty (Q)) {V=Dequeue (Q); Output V, or record the output serial number of V. for(V for each pro contact W) {if(--indegree[w]==0) Enqueue[w,q]; } } if(the number of vertices not enough to output) Error ("There is a circuit in the diagram");}
AOE (Activity on Edge) network
Critical path Issues
AOV
----------topology Sorting--------------