以下是使用邻接表存储表示的,最小生成树prim算法的应用实例。
用于演示的图如下:
#include<iostream>
#define MaxVertexNum 6
#define MAXNUM 65535
using namespace std;
//抽象数据类型
typedef char vertextype;//顶点类型
//边结点类型
typedef struct edge
{
int mark;
int no;
struct edge *next;
}edgetype;
//点结点类型
typedef struct
{
int mark;
vertextype vertex;
edgetype *firstArc;
}vertexNode;
//图
typedef struct
{
vertexNode vex[MaxVertexNum];
int n,e;
}ALGraph;
ALGraph G;
ALGraph Tree;
typedef struct
{
edgetype lowcost;//权值
int nearvex;//顶点的序号
}node;
//标记顶点是否被访问过
int visited[MaxVertexNum];
//构造邻接表
void create(ALGraph &G)
{
G.n=6;
G.vex[