Code
/* '邻接矩阵' 实现无向图的创建、深度优先遍历*/
#include
#include
#define MaxVex 100 //最多顶点个数
#define INFINITY 32768 //表示极大值,即 ∞
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
typedef char VertexType; //假设顶点数据类型为字符类型
typedef int EdgeType; //对于无权图,用1或0表示是否相邻,对带权图,则为权值类型
typedef struct
{
VertexType vertex[MaxVex]; //顶点数组
EdgeType arcs[MaxVex][MaxVex]; //邻接矩阵
int vexnum,arcnum; //图中的顶点数和边数
}Graph;
int visited[MaxVex]; //访问标志数组
/**********************各个子函数的定义*********************/
void init(Graph *G); //初始化邻接矩阵
int LocateVertex(Graph *G,VertexType v);//求顶点位置函数
int createUDG(Graph *G); //创建一个无向图
void DepthFirstSearch(Graph G, int i); //图的深度优先遍历
void TraverseGraph(Graph G);
/**************************主函数*************************/
int main()
{
Graph G;
int choice;
while(true)
{
printf("*****************Please enter your choice*****************\n\n");
printf(" choice 1:Initialization\n");
printf(" choice 2:Create Graph\n");
printf(" choice 3:Depth First Search\n");
printf(" choice 0:exit\n\n&