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