
May 4th, 2010, 10:52 AM
#1
prim's algorithm
i want to write program for prim's algorithms in VB6 but i can't becouse i am new in VB6
and they want me to do it in one week
so help me if you can
please

May 4th, 2010, 01:07 PM
#2
Re: prim's algorithm
Not very likely you would get any help this way...
Read this.
Regards,
Zachm

May 4th, 2010, 01:28 PM
#3

May 5th, 2010, 01:23 AM
#4
Re: prim's algorithm
but sir Zachm i want to tell some thing
i didn't study this subject and i dont know what is an algorithms
it just my supervisor tell me to do some thing new and i reject his idea in the biging but he tell me that i have to do it in VB6. it is easy.
then i try to under stand it until i get it in c++(i have the code for it) but i cant do it in Vb6 because i am studying the principle of it now
so help me if you can please by do it in VB6 or convert the code of c++ and this is the code in c++ :
(sory for my bad english)
#include<iostream.h>
class prims
{
private:
int n; //no of nodes
int graph_edge[250][4]; //edges in the graph
int g; //no of edges in the graph
int tree_edge[250][4]; //edges in the tree
int t; //no of edges in the tree
int s; //source node
//Partition the graph in to two sets
int T1[50],t1; // Set 1
int T2[50],t2; // Set 2
public:
void input();
int findset(int);
void algorithm();
void output();
};
void prims::input()
{
cout<<”*************************************************\n”
<<”This program implements the prims algorithm\n”
<<”*************************************************\n”;
cout<<”Enter the no. of nodes in the undirected weighted graph ::”;
cin>>n;
g=0;
cout<<”Enter the weights for the following edges ::\n”;
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
cout<<” < “<<i<<” , “<<j<<” > ::”;
int w;
cin>>w;
if(w!=0)
{
g++;
graph_edge[g][1]=i;
graph_edge[g][2]=j;
graph_edge[g][3]=w;
}
}
}
// print the graph edges
cout<<”\n\nThe edges in the given graph are::\n”;
for(i=1;i<=g;i++)
cout<<” < “<<graph_edge[i][1]
<<” , “<<graph_edge[i][2]
<<” > ::”<<graph_edge[i][3]<<endl;
}
int prims::findset(int x)
{
for(int i=1;i<=t1;i++)
if(x==T1[i])
return 1;
for(i=1;i<=t2;i++)
if(x==T2[i])
return 2;
return 1;
}
void prims::algorithm()
{
t=0;
t1=1;
T1[1]=1; //The source node
t2=n1;
int i;
for(i=1;i<=n1;i++)
T2[i]=i+1; //The reamining nodes
cout<<”\n*****The algorithm starts*****\n\n”;
while(g!=0 && t!=n1)
{
// Find the least cost edge
int min=9999;
int p;
int u,v,w;
for(i=1;i<=g;i++)
{
bool flag1=false,flag2=false;
//if u and v are in different sets
if(findset(graph_edge[i][1])!=findset(graph_edge[i][2]))
{
if(min>graph_edge[i][3])
{
min=graph_edge[i][3];
u=graph_edge[i][1];
v=graph_edge[i][2];
w=graph_edge[i][3];
p=i;
}
}
}
//break if there is no such edge
cout<<”The edge included in the tree is ::”;
cout<<” < “<<u<<” , “<<v<<” > “<<endl;
//delete the edge from graph edges
for(int l=p;l<g;l++)
{
graph_edge[l][1]=graph_edge[l+1][1];
graph_edge[l][2]=graph_edge[l+1][2];
graph_edge[l][3]=graph_edge[l+1][3];
}
g–;
//add the edge to the tree
t++;
tree_edge[t][1]=u;
tree_edge[t][2]=v;
tree_edge[t][3]=w;
//Alter the set partitions
t1++;
int m;
if(findset(v)==2)
{
T1[t1]=v;
m=v;
}
else if(findset(u)==2)
{
T1[t1]=u;
m=u;
}
int x;
for(x=1;T2[x]!=m;x++);
for(;x<t2;x++)
T2[x]=T2[x+1];
t2–;
// Print the sets
int k;
cout<<”NOW\nT1 :: “;
for(k=1;k<=t1;k++)
cout<<T1[k]<<’ ‘;
cout<<endl;
cout<<”T2 :: “;
for(k=1;k<=t2;k++)
cout<<T2[k]<<’ ‘;
cout<<endl;
cout<<”The graph edges are ::\n”;
for(i=1;i<=g;i++)
cout<<” < “<<graph_edge[i][1]
<<” , “<<graph_edge[i][2]
<<” > ::”<<graph_edge[i][3]<<endl;
cout<<endl<<endl;
}
}
void prims:utput()
{
cout<<”\nThe selected edges are ::\n”;
for(int i=1;i<=t;i++)
cout<<” < “<<tree_edge[i][1]
<<” , “<<tree_edge[i][2]
<<” > ::”<<tree_edge[i][3]<<endl;
}
int main()
{
prims obj;
obj.input();
obj.algorithm();
obj.output();
return 0;
}

May 5th, 2010, 04:09 PM
#5
Re: prim's algorithm
I don't think you got the point.
The whole point of homework is that you will learn something new by thinking, experiencing and studying yourself. If someone here did it for you, then you would miss the point of homework and of these forums.
If your supervisor makes demands that you think are unreasonable, this is no one's fault but your supervisor's, or yourself, if the demands turn out to be reasonable, so please don't throw the mercy card at us (plus, it looks bad for you).
People here will be totally willing to help you with your homework, once you at least show some effort, post some code you are having difficulty with, etc.
I am not trying to attack you, or scare you away, just point out that no one here is likely to do the whole work for you, even if they can, for the specified reasons.
This forum is for algorithms, so once you make some effort, or at least ask specific questions, you should probably post in the VB forum.
Regards,
Zachm

May 7th, 2010, 11:17 AM
#6
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
OnDemand Webinars (sponsored)
