sk's answer is technically correct. However, my experiences has been that one very rarely has a completely generic graph. Usually, there's additional information about how the graph is built that can remove the NP-completeness from a find_all_cycles() function.
A few items to look for could be:
- You don't have any edges that loopback to the same vertex.
- You can guarantee either an even or odd number of edges leading into or out of every vertex.
- You can break your graph up into sub-graphs where any cycles cannot contain vertices in more than one sub-graph.
My criteria for good software:
- Does it work?
- Can someone else come in, make a change, and be reasonably certain no bugs were introduced?