最小生成树(普里姆算法)

#include
using namespace std;
#include
#define maxSize 100
#define INF 0x3f3f3f3f
typedef struct 
{
	int no;        //顶点编号 
	char info;     //顶点其他信息 
}VertexType;
typedef struct 
{
	int edges[maxSize][maxSize];
	int n,e;                  //分别为顶点数和边数 
	VertexType vex[maxSize];  //存放结点信息 
}MGraph;
void Prim(MGraph g,int v0,int &sum)
{
	int lowcost[maxSize],vset[maxSize],v;
	int i,j,k,min;
	v=v0;
	for(i=0;i>n>>e; 
	g.n=n,g.e=e;
	memset(g.edges,INF,sizeof(g.edges));
	for(int i=0;i>a>>b>>w;
		g.edges[i][i]=0;
		g.edges[a][b]=g.edges[b][a]=w;
	}
	Prim(g,0,sum);
	cout<

 

你可能感兴趣的:(图,数据结构(天勤代码实现))