in reply to Sorting, given only comparisions

See my writeup on topological sort in Perl for code that does this. Or read all about in in Knuth's The Art of Computer Programming.

It's not Prolog or Logic Programming.