1 PROCEDURE (G: digraph)
2 Let s1 be an empty list //Source
3 Let s2 be an empty list //Sink
4 WHILE G is not empty
5 WHILE G contains a sink
6 Choose a sink u
7 Insert u to s2
8 Remove u from G
9 END WHILE
10
11 WHILE G contains a source
12 Choose a source v;
13 Append v to s1
14 Remove v from G
15 ENDWHILE
16
17 //If there are vertices with both
18 //incoming and outgoing edges,
19 //compute the difference between outdegree
20 //and indegree.
21 //Find the vertex with largest delta
22 //and append to s1
23 IF G not empty
24 Compute delta(u):delta(u) = outdeg(u) – indeg(u)
25 Choose a vertex u such as delta(u) is maximum
26 Append u to s1
27 Remove u and all its incident edges from G
28 ENDIF
29
30 ENDWHILE
31 //Concatenate S2 to S1 to form S, a vertex sequence
32 COMPUTER S by CONCATENATING S2 into S1 to form S
33
34 END PROCEDURE