#include<cstdio>
#include<iostream>
#include<malloc.h>
#define max_sum 30
using namespace std;
typedef struct Arcnode{
int adjvex;
struct Arcnode *nextarc;
}Arcnode;
typedef struct Vexnode{
char data;
struct Arcnode *firstarc;
}Vnode,AdjList[max_sum];
typedef struct Graph{
AdjList vexlist;
int vex_sum;
int arc_sum;
};
void creat_graph(Graph &g){
cout<<"输入顶点和边的个数:"<<endl;
cin>>g.vex_sum>>g.arc_sum;
for(int i = 1;i <= g.vex_sum;i++)
{
cout<<"输入字符:"<<endl;
cin>>g.vexlist[i].data;
g.vexlist[i].firstarc = NULL;
}
for(int i = 1;i <= g.arc_sum;i++)
{
cout<<"输入起点和终点:"<<endl;
int s,e;
cin>>s>>e;
Arcnode *p = new Arcnode;
p->adjvex = e;
p->nextarc = g.vexlist[s].firstarc;
g.vexlist[s].firstarc = p;
}
}
void print_graph(Graph &
邻接表(逆邻接表)创建
最新推荐文章于 2024-07-18 20:38:17 发布