#include <iostream> using namespace std; const int SIZE = 205; int n, e; struct EdgeNode { int adjvex; struct EdgeNode* next; }; struct VexNode { int adjvex; EdgeNode * firstArc; }; struct Gragh { int n, e; VexNode adjvexList[SIZE]; }; void CreateGragh(Gragh* & g) { cout<<"Begine!"<<endl; g = new Gragh; cin>>g->n>>g->e; int i; for(i=0; i<g->n; ++i) { g->adjvexList[i].adjvex = i; g->adjvexList[i].firstArc = NULL; } for(i=0; i<g->e; ++i) { int b, t; cin>>b>>t; EdgeNode* p = new EdgeNode; p->adjvex = t; p->next = g->adjvexList[b].firstArc; g->adjvexList[b].firstArc = p; EdgeNode* q = new EdgeNode; q->adjvex = b; q->next = g->adjvexList[t].firstArc; g->adjvexList[t].firstArc = q; } } void DispAdjList(Gragh* & g){ EdgeNode *p; cout<<"图的邻接表表示如下:"<<endl; int i; for(i=0; i<g->n; ++i){ cout<<"["<<i<<"]=>"; p=g->adjvexList[i].firstArc; while(p!=NULL){ cout<<"("<<p->adjvex<<")->"; p=p->next; } cout<<"^/n"; } } int main() { Gragh* g; CreateGragh(g); DispAdjList(g); return 0; }