#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
#define INFINITY 65535 //最大值∞
#define MAX_VERTEX_NUM 20 //最大顶点个数
typedef int Status;
typedef int VRType;
typedef char InfoType;
typedef int VertexType;
typedef enum {DG,DN,UDG,UDN}GraphKind; //{有向图,有向网,无向图,无向网}
typedef struct ArcCell
{
VRType adj; //VRType 是顶点关系类型。对无权图,用0或1表示相邻否;对带权图,则为权值类型
InfoType *info; //该弧相关信息的指针
}ArcCell, AdjMatrix[MAX_VERTEX_NUM][MAX_VERTEX_NUM];
typedef struct
{
VertexType vexs[MAX_VERTEX_NUM]; //顶点向量
AdjMatrix arcs; //邻接矩阵
int vexnum,arcnum; //图的当前顶点数和弧数
GraphKind kind; //图的种类标志
}MGraph;
/*******************************声明部分****************************************/
Status CreateGraph (MGraph *G);
//采用数组(邻接矩阵)表示法,构造图G
Status CreateDG(MGraph *G);
//构造有向图
Status CreateDN(MGraph *G);
//构造有向网
Status CreateUDG(MGraph *G);
//构造无向图
Status CreateUDN(MGraph *G);
//构造无向网
int LocateVex(MGraph G,VertexType v);
//确定v在G中的位置
Status PrintfArcs(MGraph G);
//输出图G的邻接矩阵
/*******************************函数部分****************************************/
Status CreateGraph (MGraph *G)
{
printf("请输入图的类型:\n");
printf("0:有向图 1:有向网 2:无向图 3:无向网\n");
scanf("%d",&(*G).kind);
switch((*G).kind)
{
case DG:
【数据结构】算法7.1-7.2 图的存储结构-数组表示法
最新推荐文章于 2023-09-18 03:56:34 发布