Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions 03-Greedy/kruskal-mst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ vector<Edge> KruskalsMST(vector<Edge>& edges, int V) {
}

int i = 0; // Index used to pick next edge
while (result.size() < V - 1) {
for (const Edge& edge : edges) {
// Pick next edge from the sorted list
Edge next_edge = edges[i++];

Expand Down Expand Up @@ -84,9 +84,13 @@ int main() {
vector<Edge> mst = KruskalsMST(edges, V);

cout << "Edges in the constructed MST: \n";
for (Edge edge : mst) {
for (const Edge& edge : mst) {
cout << edge.src << " -- " << edge.dest << " == " << edge.weight << endl;
}
if (mst.size() < V - 1) {
cout << "\nNote: The graph is disconnected. Forest generated instead of a single MST.\n";
}


return 0;
}