From 4e23439045fdedb7e1309b890ef13563df32a186 Mon Sep 17 00:00:00 2001 From: David Leal Date: Sun, 11 Jun 2023 18:22:39 +0000 Subject: [PATCH] docs: add documentation in `kruskals_minimum_spanning_tree.cpp` --- .../kruskals_minimum_spanning_tree.cpp | 48 +++++++++++++++++-- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/greedy_algorithms/kruskals_minimum_spanning_tree.cpp b/greedy_algorithms/kruskals_minimum_spanning_tree.cpp index ed7f82b72..66cb1e8fe 100644 --- a/greedy_algorithms/kruskals_minimum_spanning_tree.cpp +++ b/greedy_algorithms/kruskals_minimum_spanning_tree.cpp @@ -1,9 +1,42 @@ -#include -#include +/** + * @file + * @brief [Kruskals Minimum Spanning + * Tree](https://www.simplilearn.com/tutorials/data-structure-tutorial/kruskal-algorithm) + * implementation + * + * @details + * _Quoted from + * [Simplilearn](https://www.simplilearn.com/tutorials/data-structure-tutorial/kruskal-algorithm)._ + * + * Kruskal’s algorithm is the concept that is introduced in the graph theory of + * discrete mathematics. It is used to discover the shortest path between two + * points in a connected weighted graph. This algorithm converts a given graph + * into the forest, considering each node as a separate tree. These trees can + * only link to each other if the edge connecting them has a low value and + * doesn’t generate a cycle in MST structure. + * + * @author [coleman2246](https://github.com/coleman2246) + * @author [David Leal](https://github.com/Panqusito7) + */ -void findMinimumEdge(int INFINITY, std::array, 6> graph) { +#include /// for array +#include /// for IO operations + +/** + * @namespace + * @brief Greedy Algorithms + */ +namespace greedy_algorithms { +/** + * @brief Finds the minimum edge of the given graph. + * @param infinity Defines the infinity of the graph + * @param graph The graph that will be used to find the edge + * @returns void + */ +template +void findMinimumEdge(const int &infinity, const std::array, 6> &graph) { for (int i = 0; i < graph.size(); i++) { - int min = INFINITY; + int min = infinity; int minIndex = 0; for (int j = 0; j < graph.size(); j++) { if (graph[i][j] != 0 && graph[i][j] < min) { @@ -15,7 +48,12 @@ void findMinimumEdge(int INFINITY, std::array, 6> graph) { << std::endl; } } +} // namespace greedy_algorithms +/** + * @brief Main function + * @returns 0 on exit + */ int main() { constexpr int INFINITY = 99999; std::array, 6> graph{ @@ -26,6 +64,6 @@ int main() { INFINITY, 3, 1, 5, 0, INFINITY, INFINITY, INFINITY, INFINITY, 7, INFINITY, 0}; - findMinimumEdge(INFINITY, graph); + greedy_algorithms::findMinimumEdge(INFINITY, graph); return 0; }