//Prim 算法
#include<stdio.h>
#define MAX_VERTEX_NUM 20
const INFINITY=1000;
typedef enum {DG,DN,AG,AN}GraphKind;
typedef int AdjMatrix[MAX_VERTEX_NUM][MAX_VERTEX_NUM];
typedef struct
{
char vexs[MAX_VERTEX_NUM]; //顶点向量
AdjMatrix arcs; //邻接矩阵
int vexnum,arcnum; //图的当前顶点数和边数
GraphKind kind; //图的种类标志
}MGraph;
typedef struct
{
char vex;
int mincost;
}minside[MAX_VERTEX_NUM]; //辅助数组
int LocateVex(MGraph &G,char u);
void CreateAG(MGraph &G);
int Minimum(minside MINI,MGraph &G);
void Prim(MGraph &G,char u);
void ShowAG(MGraph &G);
int main()
{
MGraph(g);
CreateAG(g);
ShowAG(g);
Prim(g,g.vexs[0]);
return 0;
}
int LocateVex(MGraph &G,char u) //若G中存在顶点u,则返回该顶点在图中的位置;否则返回-1
{
for(int i=0;i<G.vexnum;i++)
if(u==G.vexs[i])
return i;
return -1;
}
void CreateAG(MGraph &G)
{
int i,j,k,w;
char va,vb;
pri
Prim算法求最小生成树
最新推荐文章于 2023-11-07 20:25:54 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)