算法:
input:图G
输出:一组MST T
开始
T = null;E = G.Edges;
对于G中的所有顶点,创建具有单个顶点的树t b
将T添加到T
结束于
repeat
Find an edge e ∈ E having minimum weight
such that one end belongs to t ∈ T and the other
end does not belongs to any of the trees in T
Add e to t
until e = NULL
我被固定在突出显示的块的逻辑上。我已经为顶点,边缘和树使用了简单的对象。对于它们的集合,使用对象数组。
我有代码:
Tree[] findMSF(){
T=new Tree[numofMST];
E=new Edge[C.v.length];
for(int i=0;i<E.length;i++){
E[i]=C.e[i];//E ← C.Edges
}
for(int i=0;i<B.length;i++){
t=new Tree(B[i].v);//Create a tree t having single vertex b
T[i]=t;// T ← T U t
}
do{
e=find_e(E);
}while(e!=null);
return T;
}
我需要实现find_e(E);
使用for循环。
for (int i = 1; i < 10; i++)
{
Your code
}
要更改重复的次数,请将10更改为另一个数字。