实验十四、最小生成树
1 实验目的
本实验实现最小生成树的prime算法。
2 实验内容
- 建立如图所示的邻接矩阵;
2)根据prime算法求其最小生成树,如从顶点A出发生成的最小生成树为:
利用前缀点数组完成记录最小生成树建立的过程
Code:
#include<stdio.h>
#include<stdlib.h>
#define MAX_SIZE 20
#define OK 1
#define NO 0
#define INF 0x3f3f3f3f
typedef int Status;
typedef int ElemType;
typedef char InfoType;
typedef struct
{
InfoType *info;
ElemType Vertex;
}ArcCell,*ImageTable;
typedef struct
{
ImageTable *Matrix; //临接矩阵
ArcCell vexs[MAX_SIZE]; //顶点表
int vexnum,arcnum; //统计顶点和边(弧)的个数
Status Tag; //图的种类 1,2,3,4分别对应无向图、无向网、有向图、有向网
}MGraph;
Status InitMatrix(MGraph *Node)
{
int i;
Node->Matrix=(ImageTable *)malloc(Node->vexnum*sizeof(ImageTable));
for(i=0;i<Node->vexnum;i++)
{
Node->Matrix[i]=(ImageTable)malloc(Node->vexnum*sizeof(ArcCell));
if(Node->Matrix[i]<