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+ */
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