tu.h
上传用户:gisslht
上传日期:2022-07-26
资源大小:111k
文件大小:1k
- #include<string>
- #define Max_Vertex_Num 10 //最大顶点数
- #define NULL 0
- #define TRUE 1
- #define OK 1
- #define FALSE 0
- #define ERROR -1
- #define OVERFLOW 0
- typedef char VertexType; //顶点类型
- typedef int GraphKind; //图类型
- //弧的结点结构
- /*---------------------------------------------------------------------*/
- typedef struct ArcNode
- {
- int adjvex; //该弧所指向的顶点的位置
- struct ArcNode *nextarc; //指向弧尾相同的下一条弧的指针
- }ArcNode;
- //顶点的结点结构
- /*---------------------------------------------------------------------*/
- typedef struct VNode
- {
- int degree,outdegree,indegree; //顶点的度(无向),出度,入度(有向)
- VertexType vexdata; //顶点信息
- ArcNode *firstarc; //第一个表结点的地址,即指向第一条依附该顶点的弧的指针
- }VNode, AdjList[Max_Vertex_Num];
- //图的结点结构
- /*---------------------------------------------------------------------*/
- typedef struct ALGraph
- {
- AdjList vertices; //结点数组
- int vexnum; //图的顶点数目
- int arcnum; //弧的数目
- GraphKind kind; //图的类型
- }ALGraph;
- //功能函数
- /*---------------------------------------------------------------------*/
- void CreateGraph(ALGraph &G); //创建图
- int LocateVex(ALGraph G,VertexType u); //判断顶点存在性
- void DisplayALGraph(ALGraph G); //输出图信息
- void Degree(ALGraph G); //求顶点的度
- int DFSTraverse( ALGraph G ); //深度优先遍历
- void BFSTraverse( ALGraph G, void(*Visit)(char) ); //广度优先遍历
- void print(char v);