接上篇。
此篇我们将介绍邻接表的思想及两种遍历的代码。
首先明确邻接表的存储方式:
邻接表中存在两种结构:顶点表节点和边表节点。
顶点表节点是存储当前节点,其后的一串边表节点是此点的邻接点。
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<cstring>
using namespace std;
const int MaxSize=100;
const int VERTEXNUM=20;
template<class T>
struct ArcNode
{
int adjvex;
struct ArcNode<T> *next;
};
template<class T>
struct VertexNode
{
char ver;
struct ArcNode<T> *firstedge;
};
此后的遍历仍需用到队列,故在此我们需要再写一个队列
typedef s