/* 标准文档模板 */
#include "Stdio.h"
#include "Conio.h"
int main(void)
{
float t[9][9]={{0,38.2,44,100,100,100,100,12,18.2}, //A~
{38.2,0,5.9,100,100,100,100,100,100}, //B~
{44,5.9,0,23.1,41.1,100,56,100,100}, //C~
{100,100,23.1,0,67,98.7,100,100,100}, //D~
{100,100,41.1,67,0,85,10.5,100,100}, //E~
{100,100,100,98.7,85,0,100,100,79}, //F~
{100,100,56,100,10.5,100,0,52.5,100}, //G~
{12,100,100,100,100,100,52.5,0,8.7}, //H~
{18.2,100,100,100,100,79,100,8.7,0}}; //I~
//用邻接矩阵来存储网?
int tree[8][2]; //存储最小生成树的边 形式(i,j)
int lowcost[8]; //剩余顶点与closevertex[]中顶点构成的边的最小权掷, 0表示顶点A已经存入closevertex[]
int closevertex[8]; //用来存储最小权值边的起点
int i,j,k,mincost;
int maxcost=1000;
for(i=1;i<9;i++)
{
lowcost[i]=t[0][i];
closevertex[i]=0;
} //初始化
lowcost[0]=0; //从0号顶点出发生成树
closevertex[0]=0;
for(i=1;i<9;i++)
{mincost=maxcost; //maxcost表示权值无穷大即 2点间不直接相连
j=1;k=1;
while(j<9)
{ if(lowcost[j]<mincost&&lowcost[j]!=0)
{ mincost=lowcost[j];
k=j;
}
j++;
}
printf("顶点的序号=%d 边的权值=%d\n",k,mincost);
lowcost[k]=0; //表示k号顶点进入closevertex[]中
for(j=1;j<9;j++)
if(t[k][j]<lowcost[j])
{lowcost[j]=t[k][j];
closevertex[j]=k;
}
}
}
getch();
return 0;
}
运行说第一句二维数组语法错误,后面错误更多,帮我看看啊^ 这是用PRIME算法建立最小生成树 ,上面是邻接矩阵存储城市通道网图,最后要求权值最小的通道,而且通道数最小 即9个城市,最小8个通道.