CFanatic

Go Back   CFanatic > Programming > C++ Programming

C++ code for Kruskal Algorithm topic posted under C++ Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 09-11-2006, 11:53 PM
Junior Member
 
Join Date: Sep 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
ravi_forum is on a distinguished road
| More
C++ code for Kruskal Algorithm

Sir,

I wanted to know the implementation code for krushkal algorithm in C++.

Anyone can help me to give the code.
ThnQ
Reply With Quote
  #2  
Old 12-26-2006, 01:22 AM
Junior Member
 
Join Date: Dec 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Aztec is on a distinguished road
| More
Re: C++ code for Kruskal Algorithm

Quote:
Originally Posted by ravi_forum View Post
Sir,

I wanted to know the implementation code for krushkal algorithm in C++.

Anyone can help me to give the code.
ThnQ
Take a look here
Reply With Quote
  #3  
Old 12-26-2006, 02:42 AM
Junior Member
 
Join Date: Sep 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
ravi_forum is on a distinguished road
| More
Re: C++ code for Kruskal Algorithm

Thanks for the link.
Reply With Quote
  #4  
Old 11-10-2007, 01:48 PM
Junior Member
 
Join Date: Nov 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Pratish is on a distinguished road
| More
Re: C++ code for Kruskal Algorithm

Quote:
Originally Posted by Aztec View Post
Take a look here
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...
Reply With Quote
  #5  
Old 11-11-2007, 01:12 PM
Junior Member
 
Join Date: Nov 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Pratish is on a distinguished road
| More
Re: C++ code for Kruskal Algorithm

Quote:
Originally Posted by ravi_forum View Post
Sir,

I wanted to know the implementation code for krushkal algorithm in C++.

Anyone can help me to give the code.
ThnQ
uiyityyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
Reply With Quote
  #6  
Old 11-12-2007, 12:20 AM
shabbir's Avatar
Administrator
 
Join Date: Sep 2006
Posts: 1,225
Thanks: 79
Thanked 71 Times in 48 Posts
shabbir has a spectacular aura aboutshabbir has a spectacular aura about
| More
Re: C++ code for Kruskal Algorithm

Quote:
Originally Posted by Pratish View Post
uiyityyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
Make sure you do not make posts like this one or we may be forced to ban you.
Reply With Quote
  #7  
Old 08-26-2011, 12:15 PM
Junior Member
 
Join Date: Aug 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
hosam is on a distinguished road
| More
Re: C++ code for Kruskal Algorithm

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
Reply With Quote
  #8  
Old 10-25-2011, 01:48 AM
Junior Member
 
Join Date: Aug 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Jacobhine is on a distinguished road
| More
Re: C++ code for Kruskal Algorithm

Thanks for the link Aztec, it is helpful
Reply With Quote
  #9  
Old 10-27-2011, 03:05 AM
Junior Member
 
Join Date: Oct 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Linda87st is on a distinguished road
| More
Re: C++ code for Kruskal Algorithm

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
Reply With Quote
  #10  
Old 11-25-2011, 12:00 PM
pravinkandala's Avatar
Junior Member
 
Join Date: Nov 2011
Location: Hyderabad, India
Posts: 4
Thanks: 0
Thanked 1 Time in 1 Post
pravinkandala is on a distinguished road
| More
Re: C++ code for Kruskal Algorithm

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

Last edited by shabbir; 11-25-2011 at 11:18 PM. Reason: Code Blocks
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Compile C code in Linux Tlhokomelo C Programming 5 11-23-2007 10:50 AM
Lookover this code please minipwn C++ Programming 1 06-27-2007 10:49 PM
algorithm Wajahat Introduce yourself 4 05-22-2007 03:19 AM
C# Code ShahdaaD C# Programming 0 01-01-2007 04:47 AM
Algorithm of lock (obj) { ...} statement in C# Hyun-jik-Bae C# Programming 0 09-29-2006 06:46 AM



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.