From d8045750f393175e29411654d7a4ae524feb6836 Mon Sep 17 00:00:00 2001 From: iAshishChauhan Date: Wed, 30 Oct 2019 19:55:34 +0530 Subject: [PATCH] Kruskals Algo --- Algorithms/Graphs/cpp/Kruskals.cpp | 62 ++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Algorithms/Graphs/cpp/Kruskals.cpp diff --git a/Algorithms/Graphs/cpp/Kruskals.cpp b/Algorithms/Graphs/cpp/Kruskals.cpp new file mode 100644 index 00000000..9061070d --- /dev/null +++ b/Algorithms/Graphs/cpp/Kruskals.cpp @@ -0,0 +1,62 @@ +#include +using namespace std; +struct edge{ + int src,dest,wt; +}; +bool cmp(edge e1,edge e2) +{ + return e1.wt < e2.wt; +} +int getParent(int v,int parent[]){ + if(parent[v] == v) + return v; + return getParent(parent[v],parent); +} +int main() +{ + int V, E, tempX, tempY; + cin >> V >> E; + + /* + + Write Your Code Here + Complete the Rest of the Program + You have to Print the output yourself + + */ + edge edges[E]; + for(int i=0;i> edges[i].src >> edges[i].dest >> edges[i].wt; + } + sort(edges,edges+E,cmp); + edge output[V-1]; + int k=0; + int count = 0; + int parent[V]; + for(int i=0;i