TheAlgorithms-C-Plus-Plus/greedy_algorithms/kruskals_minimum_spanning_tree.cpp
x0rld 234a29939a
fix: remove using namespace std (#1264)
Remove `using namespace std;` in greedy_algorithms/kruskals_minimum_spanning_tree.cpp

* remove using namespace std

* change static C array to vector

* change vector to array and remove global variable
2020-10-19 16:40:03 -05:00

31 lines
909 B
C++

#include <iostream>
#include <array>
void findMinimumEdge(int INFINITY, std::array< std::array< int ,6 >,6 > graph) {
for (int i = 0; i < graph.size(); i++) {
int min = INFINITY;
int minIndex = 0;
for (int j = 0; j < graph.size(); j++) {
if (graph[i][j] != 0 && graph[i][j] < min) {
min = graph[i][j];
minIndex = j;
}
}
std::cout << i << " - " << minIndex << "\t" << graph[i][minIndex] << std::endl;
}
}
int main() {
constexpr int INFINITY = 99999;
std::array< std::array< int ,6 >,6 >graph
{0, 4, 1, 4, INFINITY, INFINITY,
4, 0, 3, 8, 3, INFINITY,
1, 3, 0, INFINITY, 1, INFINITY,
4, 8, INFINITY, 0, 5, 7,
INFINITY, 3, 1, 5, 0, INFINITY,
INFINITY, INFINITY, INFINITY, 7, INFINITY, 0};
findMinimumEdge(INFINITY,graph);
return 0;
}