#include<iostream>
#include<vector>
#include<queue>
using namespace std;
struct ArcNode{ //弧结点结构
int adjvex; //邻接顶点
ArcNode *nextarc; //下一条弧
};
template <class T>
struct VertextNode{ //表头结点结构
T Vertext; //顶点
ArcNode* firstArc; //第一条弧
};
const int MAXSIZE=10;
template<class T>
class ALGraph{
public:
ALGraph(T a[],int n,int e);
~ALGraph();
void DFS(int v);
void BFS(int v);
vector<int> visited;
private:
VertextNode<T> adjlist[MAXSIZE]; //顶点
int vNum,arcNum; //顶点和弧的数目
};
template <class T>
ALGraph<T>::ALGraph(T a[],int n,int e){
vNum=n;
arcNum=e;
visited.assign(vNum,0);
for(int k=0;k<n;k++){ //k是局部变量
adjlist[k].Vertext=a[k]; //初始化顶点
adjlist[k].firstArc=NULL; //初始化弧
}
cout<<"Input the vertexts of each arc."<<endl;
int i,j;
for(int k=0;k<e;k++){
cin>>i>>j;
ArcNode *arc=new ArcNode;
arc->adjvex=j;
arc->nextarc=adjlist[i].firstArc; //头插法建立链表
adjlist[i].firstArc=arc;
}
}
/*可发看到建立邻接表的时间复杂度为O(n+e)*/