邻接矩阵和邻接表
邻接矩阵
#include<iostream>
using namespace std;
#define INIFNITY INIT_MAX
#define MAX_VERTEX_NUM 20
typedef int VRType;
typedef int InfoType;
typedef int VertexType;
typedef enum {
DG,
DN,
AG,
AN,
}GraphKind;
typedef struct ArcCell {
VRType adj;
InfoType* pInfo;
}ArcCell,AdjMatrax[MAX_VERTEX_NUM][MAX_VERTEX_NUM];
typedef struct {
VertexType vexs[MAX_VERTEX_NUM];
AdjMatrax arcs;
int Vernum, arcnum;
GraphKind kind;
};
邻接表
#include<iostream>
using namespace std;
#define MAX_VERTEX_NUM 20
typedef int VertexType;
typedef int AdjList;
typedef struct ArcNode {
int adjvex;
struct ArcNode* nextarc;
}ArcNode;
typedef struct VNode {
VertexType data;
ArcNode* finrstarc;
}Vnode,AdjList[MAX_VERTEX_NUM];
typedef struct {
AdjList vertices;
int vexnum, arcnum;
int kind;
}ALGraph;