tu.h
上传用户:gisslht
上传日期:2022-07-26
资源大小:111k
文件大小:1k
源码类别:

图形图象

开发平台:

Visual C++

  1. #include<string>
  2. #define Max_Vertex_Num 10   //最大顶点数
  3. #define NULL 0
  4. #define TRUE 1
  5. #define OK 1
  6. #define FALSE 0
  7. #define ERROR -1
  8. #define OVERFLOW 0
  9. typedef char VertexType;  //顶点类型
  10. typedef int GraphKind;  //图类型
  11. //弧的结点结构
  12. /*---------------------------------------------------------------------*/
  13. typedef struct ArcNode
  14. int adjvex; //该弧所指向的顶点的位置
  15. struct ArcNode *nextarc; //指向弧尾相同的下一条弧的指针
  16. }ArcNode;
  17. //顶点的结点结构
  18. /*---------------------------------------------------------------------*/
  19. typedef struct VNode
  20. {
  21. int degree,outdegree,indegree; //顶点的度(无向),出度,入度(有向) 
  22. VertexType vexdata; //顶点信息
  23. ArcNode *firstarc; //第一个表结点的地址,即指向第一条依附该顶点的弧的指针
  24. }VNode, AdjList[Max_Vertex_Num];
  25. //图的结点结构
  26. /*---------------------------------------------------------------------*/
  27. typedef struct ALGraph
  28. {
  29. AdjList vertices; //结点数组
  30. int vexnum; //图的顶点数目
  31. int arcnum; //弧的数目
  32. GraphKind kind; //图的类型
  33. }ALGraph;
  34. //功能函数
  35. /*---------------------------------------------------------------------*/
  36. void CreateGraph(ALGraph &G); //创建图
  37. int LocateVex(ALGraph G,VertexType u);   //判断顶点存在性
  38. void DisplayALGraph(ALGraph G); //输出图信息
  39. void Degree(ALGraph G); //求顶点的度
  40. int DFSTraverse( ALGraph G ); //深度优先遍历
  41. void BFSTraverse( ALGraph G, void(*Visit)(char) );  //广度优先遍历
  42. void print(char v);