问题描述
使用邻接表存储下图所示无向图,使用深度优先搜索遍历无向图上的各节点
解题思路
1、创建一个邻接表接受无向图信息
程序实现
#include
#include
#define MAXVEX 10
#define TRUE 1
#define FALSE 0
/* Status是函数的类型,其值是函数结果状态代码,如OK等 */
typedef int Status;
/* 顶点类型应由用户定义 */
typedef char VertexType;
/* 边上的权值类型应由用户定义 */
typedef int EdgeType;
/* 邻接表的数据结构 */
typedef struct EdgeNode {
// 邻接点域,存储该顶点对应的下标
int adjvex;
// 链域,指向下一个邻接点
struct EdgeNode *next;
} EdgeNode;
// 顶点表结点
typedef struct VertexNode {
// 顶点域,存储顶点信息
VertexType data;
// 边表头指针
EdgeNode *firstedge;
} VertexNode, AdjList