Skip to content

Commit b480ddb

Browse files
Panquesito7github-actions[bot]realstealthninja
authored
docs: add documentation in kruskals_minimum_spanning_tree.cpp (TheAlgorithms#2482)
* docs: add documentation in `kruskals_minimum_spanning_tree.cpp` * clang-format and clang-tidy fixes for 4e23439 * chore: remove myself as an author * chore: `std::endl` -> `\n` --------- Co-authored-by: github-actions[bot] <github-actions@users.noreply.github.com> Co-authored-by: realstealthninja <68815218+realstealthninja@users.noreply.github.com>
1 parent 882ba11 commit b480ddb

File tree

1 file changed

+44
-6
lines changed

1 file changed

+44
-6
lines changed
Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,42 @@
1-
#include <array>
2-
#include <iostream>
1+
/**
2+
* @file
3+
* @brief [Kruskals Minimum Spanning
4+
* Tree](https://www.simplilearn.com/tutorials/data-structure-tutorial/kruskal-algorithm)
5+
* implementation
6+
*
7+
* @details
8+
* _Quoted from
9+
* [Simplilearn](https://www.simplilearn.com/tutorials/data-structure-tutorial/kruskal-algorithm)._
10+
*
11+
* Kruskal’s algorithm is the concept that is introduced in the graph theory of
12+
* discrete mathematics. It is used to discover the shortest path between two
13+
* points in a connected weighted graph. This algorithm converts a given graph
14+
* into the forest, considering each node as a separate tree. These trees can
15+
* only link to each other if the edge connecting them has a low value and
16+
* doesn’t generate a cycle in MST structure.
17+
*
18+
* @author [coleman2246](https://github.com/coleman2246)
19+
*/
320

4-
void findMinimumEdge(int INFINITY, std::array<std::array<int, 6>, 6> graph) {
21+
#include <array> /// for array
22+
#include <iostream> /// for IO operations
23+
24+
/**
25+
* @namespace
26+
* @brief Greedy Algorithms
27+
*/
28+
namespace greedy_algorithms {
29+
/**
30+
* @brief Finds the minimum edge of the given graph.
31+
* @param infinity Defines the infinity of the graph
32+
* @param graph The graph that will be used to find the edge
33+
* @returns void
34+
*/
35+
template <typename T>
36+
void findMinimumEdge(const int &infinity,
37+
const std::array<std::array<T, 6>, 6> &graph) {
538
for (int i = 0; i < graph.size(); i++) {
6-
int min = INFINITY;
39+
int min = infinity;
740
int minIndex = 0;
841
for (int j = 0; j < graph.size(); j++) {
942
if (graph[i][j] != 0 && graph[i][j] < min) {
@@ -12,10 +45,15 @@ void findMinimumEdge(int INFINITY, std::array<std::array<int, 6>, 6> graph) {
1245
}
1346
}
1447
std::cout << i << " - " << minIndex << "\t" << graph[i][minIndex]
15-
<< std::endl;
48+
<< "\n";
1649
}
1750
}
51+
} // namespace greedy_algorithms
1852

53+
/**
54+
* @brief Main function
55+
* @returns 0 on exit
56+
*/
1957
int main() {
2058
constexpr int INFINITY = 99999;
2159
std::array<std::array<int, 6>, 6> graph{
@@ -26,6 +64,6 @@ int main() {
2664
INFINITY, 3, 1, 5, 0, INFINITY,
2765
INFINITY, INFINITY, INFINITY, 7, INFINITY, 0};
2866

29-
findMinimumEdge(INFINITY, graph);
67+
greedy_algorithms::findMinimumEdge(INFINITY, graph);
3068
return 0;
3169
}

0 commit comments

Comments
 (0)