#define infinity 1000000
#define max_vertexes 5
typedef int Graph[max_vertexes][max_vertexes];
void prim(Graph G,int vcount,int father[])
{
int i,j,k;
int lowcost[max_vertexes],closeset[max_vertexes],used[max_vertexes];
for (i=0;i<vcount;i++)
{
lowcost[i]=G[0][i];
closeset[i]=0;
used[i]=0;
father[i]=-1;
}
used[0]=1;
for (i=1;i<vcount;i++)
{
j=0;
while (used[j])
j++;
for (k=0;k<vcount;k++)
if ((!used[k])&&(lowcost[k]<lowcost[j]))
j=k;
father[j]=closeset[j];
used[j]=1;
for (k=0;k<vcount;k++)
if (!used[k]&&(G[j][k]<lowcost[k]))
{
lowcost[k]=G[j][k];
closeset[k]=j;
}
}
}
Prim算法求最小生成树
最新推荐文章于 2012-09-09 19:23:58 发布
6491

被折叠的 条评论
为什么被折叠?



