Sir, I wanted to know the implementation code for krushkal algorithm in C++. Anyone can help me to give the code. ThnQ
I wanted to know the implementation code for krushkal algorithm, Breadth first search and index sequencial search in C++/C/Java. I also want to knw the code for converting Infix expression to postfix and prefix expression using stack and binary tree...
Thank you very much for helping us ... and I hope to continue this site in the production and the continuation of Members to work together to build a new minds in this world .. and far from politics
Thank you very much for helping us ... and I hope to continue this site in the production and the continuation of Members to work together to build a new minds in this world .. and far from politics
Code: /* Write C++ programs to implement the Kruskal’s algorithm to generate a minimum cost spanning tree */ #include<iostream> #include<conio.h> #include<stdlib.h> using namespace std; int cost[10][10],i,j,k,n,m,c,visit,visited[10],l,v,count,count1,vst,p; main() { int dup1,dup2; cout<<"enter no of vertices"; cin >> n; cout <<"enter no of edges"; cin >>m; cout <<"EDGE Cost"; for(k=1;k<=m;k++) { cin >>i >>j >>c; cost[i][j]=c; cost[j][i]=c; } for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(cost[i][j]==0) cost[i][j]=31999; visit=1; while(visit<n) { v=31999; for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(cost[i][j]!=31999 && cost[i][j]<v && cost[i][j]!=-1 ) { int count =0; for(p=1;p<=n;p++) { if(visited[p]==i || visited[p]==j) count++; } if(count >= 2) { for(p=1;p<=n;p++) if(cost[i][p]!=31999 && p!=j) dup1=p; for(p=1;p<=n;p++) if(cost[j][p]!=31999 && p!=i) dup2=p; if(cost[dup1][dup2]==-1) continue; } l=i; k=j; v=cost[i][j]; } cout <<"edge from " <<l <<"-->"<<k; cost[l][k]=-1; cost[k][l]=-1; visit++; int count=0; count1=0; for(i=1;i<=n;i++) { if(visited[i]==l) count++; if(visited[i]==k) count1++; } if(count==0) visited[++vst]=l; if(count1==0) visited[++vst]=k; } } OUTPUT enter no of vertices4 enter no of edges4 EDGE Cost 1 2 1 2 3 2 3 4 3 1 3 3 edge from 1–>2edge from 2–>3edge from 1–>3
hii sir, plz give me the explanation of this code.. i have some doubts in this code.. thanks. Regards sourabh khandelwal
Hello,everyone,!I am new here .Today is my first day.I'm from China.My English is not very good.Because I majorde in programming and very like it.I come here.I want to make freinds with people who spaeak English.My e-mail is lishihong108@gmail.com.If you interested to me,please e-mail to me.I wait your voice.Good luck to you!
Google "kruskal boost mfc" for a C++ / MFC application that allows the user to interactively add nodes, links etc and uses the Boost Graph library to calculate the minimal spanning tree.