mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
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
This commit is contained in:
parent
7f97119f8a
commit
234a29939a
@ -1,31 +1,30 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
#include <array>
|
||||
|
||||
#define V 6
|
||||
#define INFINITY 99999
|
||||
|
||||
int graph[V][V] = {{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}};
|
||||
|
||||
void findMinimumEdge() {
|
||||
for (int i = 0; i < V; i++) {
|
||||
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 < V; j++) {
|
||||
for (int j = 0; j < graph.size(); j++) {
|
||||
if (graph[i][j] != 0 && graph[i][j] < min) {
|
||||
min = graph[i][j];
|
||||
minIndex = j;
|
||||
}
|
||||
}
|
||||
cout << i << " - " << minIndex << "\t" << graph[i][minIndex] << "\n";
|
||||
std::cout << i << " - " << minIndex << "\t" << graph[i][minIndex] << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
findMinimumEdge();
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user