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+ * @author [David Leal](https://github.com/Panqusito7)
20+ */
321
4- void findMinimumEdge (int INFINITY, std::array<std::array<int , 6 >, 6 > graph) {
22+ #include < array> // / for array
23+ #include < iostream> // / for IO operations
24+
25+ /* *
26+ * @namespace
27+ * @brief Greedy Algorithms
28+ */
29+ namespace greedy_algorithms {
30+ /* *
31+ * @brief Finds the minimum edge of the given graph.
32+ * @param infinity Defines the infinity of the graph
33+ * @param graph The graph that will be used to find the edge
34+ * @returns void
35+ */
36+ template <typename T>
37+ void findMinimumEdge (const int &infinity, 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) {
@@ -15,7 +48,12 @@ void findMinimumEdge(int INFINITY, std::array<std::array<int, 6>, 6> graph) {
1548 << std::endl;
1649 }
1750}
51+ } // namespace greedy_algorithms
1852
53+ /* *
54+ * @brief Main function
55+ * @returns 0 on exit
56+ */
1957int 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