Before you start throwing links to wikipedia and blogs in my face, please hear me out.
I’m trying to find the optimal algorithm/function to do a dependency sort on… stuff. Each item has a list of its dependencies.
I would like to have something iterator-based, but that’s not very important.
What is important is that the algorithm points out exactly which items are part of the dependency cycle. I’d like to give detailed error information in this case.
Practically, I’m thinking of subclassing my items from a “dependency node” class, which has the necessary booleans/functions to get the job done. Cool (but descriptive) names are welcome :)
It’s normally called a topological sort. Most books/papers/whatever that cover topological sorting will also cover cycle detection as a matter of course.