图的邻接表结构图:
代码部分:
adj_list_graph.h
#ifndef _ADJ_LIST_GRAPH_H
#define _ADJ_LIST_GRAPH_H
#include <stdio.h>
#include <stdlib.h>
#define GRAPH_NODE_INF (-1)
#define GRAPH_ERR (-1)
#define GRAPH_SUCCESS 0
typedef char VertexType;
typedef struct _edge_node {
VertexType data;
int weight;
struct _edge_node *next;
}EdgeNode, *PEdgeNode;
typedef struct _vertex_node {
VertexType data;
PEdgeNode head;
}VertexNode, *PVertexNode;
typedef struct _adj_graph {
PVertexNode node;
int edgeSize;
int nodeSize;
}AdjGraph, *PAdjGraph;
/* 初始化一个无向图 */
PAdjGraph GraphInit();
#endif
adj_list_graph.c
#include