/** * @file cycle_detection.h * @brief Cycle detection and topological sorting for directed graphs. * @details This module implements Kahn's algorithm to detect cycles in * directed graphs and perform topological sorting. A topological * sort is only possible for acyclic graphs (DAGs). */ #ifndef CYCLE_DETECTION_H #define CYCLE_DETECTION_H #include "graph.h" /** * @brief Detects cycles in a directed graph and performs topological sorting. * * @param g Pointer to the directed graph to analyze. * Must not be NULL. * * @details Prints to stdout whether the given graph has a cycle; * in that case in prints 'CYCLE DETECTED!', * else it prints the graph in topological sorting * i.e. '4, 0, 1, 3, 2'. * * @note The input graph @p g may be modified during execution. The function * alters vertex in-degree counts and neighbor lists as part of the * algorithm. If the original graph structure must be preserved, the * caller should provide a copy. * * @see Graph * @see Vertex */ void cycle_detection(Graph *g); #endif // !CYCLE_DETECTION_H