Prim算法求图的最小生成树
图的存储方式为邻接矩阵
#include
#include
#define MAX_VERTEX_NUM 10
#define MAX_ARC_LEN 1000
#define INFINITY 10000
/*
测试数据:
0 6 1 5 0 0
6 0 5 0 3 0
1 5 0 5 6 4
5 0 5 0 0 2
0 3 6 0 0 6
0 0 4 2 6 0
*/
/*
0 4 3 0 0 0 0 0
4 0 5 5 9 0 0 0
3 5 0 5 0 0 0 5
0 5 5 0 7 6 5 4
0 9 0 7 0 3 0 0
0 0 0 6 3 0 2 0
0 0 0 5 0 2 0 6
0 0 5 4 0 0 6 0*/
typedef struct{
int adjvex;
int lowcost;
}closedge;
typedef struct{
int **arc;
int vexnum,arcnum;
}Graph;
int minimum(closedge close[],int n){
int min=MAX_ARC_LEN,i,k;
for(i=0;i=close[i].lowcost){
min=close[i].lowcost;
k=i;
}
}
return k;
}
void Prim(Graph G,int u){
int i,j,k=u;
closedge close[G.vexnum];
for(j=0;j