How do you implement Knuth's Toposort in C?

Solution 1:

If you read Knuth's TAOCP (The Art of Computer Programming) Volume 1, Section 2.2.3 in the 3rd Edn, you'll find Knuth's "Algorithm T (Topological sort)" and also the comment:

A topological sorting technique similar to Algorithm T (but without the important feature of the queue links) was first published by A. B. Kahn, CACM 5 (1962), 558-562.

This indicates that Knuth's Algorithm T is different from Kahn's algorithm.