求大神帮我改下这个程序,prim算法求最小生成树的,谢谢
#include<iostream.h>#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#define Max 30
typedef struct
{
int quanzhi;
}leixing[Max][Max];
typedef struct
{
int dingdian[Max];
leixing juzhen;
int dianshu,bianshu;
}Graph;
struct
{
int adjvex;
int lowcost;
}closedge[Max];
void Creat(Graph *G)
{
int i,j,e,w;
cout<<"请输入点数和边数:";
cin>>(*G).dianshu>>(*G).bianshu;
for(i=0;i<(*G).dianshu;i++)
cin>>(*G).dingdian[i];
for(i=0;i<(*G).dianshu;i++)
for(j=0;j<(*G).dianshu;j++)
(*G).juzhen[i][j].quanzhi=0;
for(e=0;e<(*G).bianshu;e++)
{
cout<<"请输入边(i,j)及边上的权值w:";
cin>>i>>j>>w;
(*G).juzhen[i][j].quanzhi=(*G).juzhen[j][i].quanzhi=w;
}
}
void display(Graph *G)
{
int i,j;
cout<<"城市编号名:"<<endl;
for(i=0;i<(*G).dianshu;i++)
cout<<(*G).dingdian[i]<<" ";
cout<<endl;
cout<<"该城市的邻接矩阵为:"<<endl;
for(i=0;i<(*G).dianshu;i++){
for(j=0;j<(*G).dianshu;j++)
cout<<(*G).juzhen[i][j].quanzhi<<" ";
cout<<endl;
}
}
int MinNum(Graph *G)
{
int i,j=0,k=0,min=0;
for(i=0; i<(*G).dianshu; i++)
if(closedge[i].lowcost!=0)
{
min=closedge[i].lowcost;
k=i;
break;
}
for(j=i+1;j<(*G).dianshu;j++)
if(closedge[j].lowcost!=0)
{
if(min>=closedge[j].lowcost)
{
min=closedge[j].lowcost;
k=j;
}
}
return k;
}
int VerIndex(Graph *G,int v)
{
int i;
for(i=0;i<(*G).dianshu;i++)
if((*G).dingdian[i]==v)
return i;
return -1;
}
void Prim(Graph *G,char v)
{
int i,j,k;
k=VerIndex(G,v);
for(i=0;i<(*G).dianshu;i++)
if(i!=k)
{
closedge[i].lowcost=(*G).juzhen[k][i].quanzhi;
closedge[i].adjvex=k;
}
closedge[k].lowcost=0;
for(i=0;i<(*G).dianshu;i++)
{
k=MinNum(G);
cout<<closedge[k].adjvex<<"--"<<(*G).dingdian[k]<<endl;
closedge[k].lowcost=0;
}
for(j=0;j<(*G).dianshu;j++)
if((*G).juzhen[k][j].quanzhi<closedge[j].lowcost)
{
closedge[j].lowcost=(*G).juzhen[k][j].quanzhi;
closedge[j].adjvex=k;
}
}
int main()
{
Graph G;
int v;
Creat(&G);
display(&G);
cout<<"请输入出发点:";
cin>>v;
Prim(&G,v);
return 0;
}