|
|
|
|
Notice:
|
|
|
Every edge in the graph goes from a vertex with a smaller index to one with a larger index
|
|
|
i = 1;
while ( G ≠ &empty )
{
Let x = vertex in G with indeg(x) = 0;
Label x with "i";
i++;
Delete all edges (x, z) from G;
}
|
Stack S = contains vertices with indeg = 0
(these vertices are ready to be labeled)
==============================================================
S = ∅ ; // Initialize the stack
/* ---------------------------------------
Compute the "indegree" for each vertex
--------------------------------------- */
for ( each vertex x ∈ G )
{
incounter[x] = incoming degree of x;
}
/* ---------------------------------------
Find vertices with indeg = 0
--------------------------------------- */
for ( each vertex x ∈ G )
{
if ( incounter[x] == 0 )
push(x);
}
i = 1; // Initial label
/* ---------------------------------------
Label the next vertex in S
--------------------------------------- */
while ( S ≠ &empty )
{
u = S.pop();
Label u with "i";
i++;
/* ------------------------------------
Update indegree of affected nodes
------------------------------------ */
for ( each edge (u, z) ) do
{
incounter[z]--;
if ( incounter[z] == 0 )
S.push(z); // z is ready to be numbered
}
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|