docs: add documentation in kruskals_minimum_spanning_tree.cpp

This commit is contained in:
David Leal 2023-06-11 18:22:39 +00:00
parent 26f6e98d9e
commit 4e23439045

View File

@ -1,9 +1,42 @@
#include <array> /**
#include <iostream> * @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)._
*
* Kruskals 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
* doesnt 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<std::array<int, 6>, 6> graph) { #include <array> /// for array
#include <iostream> /// 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 <typename T>
void findMinimumEdge(const int &infinity, const std::array<std::array<T, 6>, 6> &graph) {
for (int i = 0; i < graph.size(); i++) { for (int i = 0; i < graph.size(); i++) {
int min = INFINITY; int min = infinity;
int minIndex = 0; int minIndex = 0;
for (int j = 0; j < graph.size(); j++) { for (int j = 0; j < graph.size(); j++) {
if (graph[i][j] != 0 && graph[i][j] < min) { if (graph[i][j] != 0 && graph[i][j] < min) {
@ -15,7 +48,12 @@ void findMinimumEdge(int INFINITY, std::array<std::array<int, 6>, 6> graph) {
<< std::endl; << std::endl;
} }
} }
} // namespace greedy_algorithms
/**
* @brief Main function
* @returns 0 on exit
*/
int main() { int main() {
constexpr int INFINITY = 99999; constexpr int INFINITY = 99999;
std::array<std::array<int, 6>, 6> graph{ std::array<std::array<int, 6>, 6> graph{
@ -26,6 +64,6 @@ int main() {
INFINITY, 3, 1, 5, 0, INFINITY, INFINITY, 3, 1, 5, 0, INFINITY,
INFINITY, INFINITY, INFINITY, 7, INFINITY, 0}; INFINITY, INFINITY, INFINITY, 7, INFINITY, 0};
findMinimumEdge(INFINITY, graph); greedy_algorithms::findMinimumEdge(INFINITY, graph);
return 0; return 0;
} }