#include<iostream>
using namespace std;
#define MAX_VERTEX 10 //图的最大顶点数
struct ArcNode //边表
{
int adjvex;
ArcNode *next;
};
struct VertNode //顶点表
{
char vert;
ArcNode*firstEdge;
};
class CGraph
{
private:
VertNode adjList[MAX_VERTEX];
int vertNum,arcNum;
public:
CGraph(char v[],int n,int e);
~CGraph();
void DFS();
void BFS();
/*void InputInfo();*/
void Print();
};
CGraph::CGraph(char v[],int n,int e)
{
cout<<"v="<<v<<" n="<<n<<" e="<<e<<'\n';
vertNum = n;
arcNum = e;
for(int i = 0;i<vertNum;i++)
{
adjList[i].vert = v[i];
adjList[i].firstEdge = NULL;
}
char vi,vj;
cout<<"输入顶点编号:"<<endl;
for(int i = 0; i< arcNum;i++)
{
//输入边的信息存储在边表中
cin>>vi>>vj; //输入边依附的两个顶点的编号 vi起点vj终点
ArcNode *s = new ArcNode;
s->adjvex = vj;
s->next = adjList[vi].firstEdge;
adjList[vi].firstEdge = s;
}
}
CGraph::~CGraph()
{
}
//void CGraph::InputInfo()
//{
// char vi,vj;
// cout<<"输入顶点编号:"<<endl;
// for(int i = 0; i< arcNum;i++)
// {
// //输入边的信息存储在边表中
// cin>>vi>>vj; //输入边依附的两个顶点的编号 vi起点vj终点
// ArcNode *s = new ArcNode;
// s->adjvex = vj;
// s->next = adjList[vi].firstEdge;
// adjList[vi].firstEdge = s;
// }
//}
void CGraph::Print()
{
ArcNode *p = nullptr;
for(int i = 0; i<vertNum;i++)
{
p = adjList[i].firstEdge;
while(p)
{
cout<<adjList[i].vert;
cout<<"->";
cout<<p->adjvex<<endl;
p = p->next;
}
}
}
int main()
{
int n,e;
cout<<"输入顶点数和边数"<<endl;
cin>>n>>e;
char v[MAX_VERTEX];
cout<<"输入顶点"<<endl;
for(int i = 0;i<n;i++)
{
cin>>v[i];
}
CGraph graph2(v,n,e);
/*graph2.InputInfo();*/
graph2.Print();
system("pause");
return 0;
}