aboutsummaryrefslogtreecommitdiff
path: root/src/cycle_detection.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/cycle_detection.h33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/cycle_detection.h b/src/cycle_detection.h
index df9607e..e5e0220 100644
--- a/src/cycle_detection.h
+++ b/src/cycle_detection.h
@@ -1,13 +1,34 @@
+/**
+ * @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"
-// Runs Kahn's algorithm on the graph, and outputs 'CYCLE DETECTED!\n'
-// if a DAG cannot be created, or the vertices as a list fx. '4, 0, 1, 3, 2\n'
-// representing an ordering in the DAG.
-// The output is printed to stdout.
-// The input may be altered in the process.
+/**
+ * @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
+#endif // !CYCLE_DETECTION_H