#define MAX_VERTEXT_NUM 20
typedef struct edge{ /*边定义*/
int from,to,weight;
}Edge,*Edged;
typedef struct ArcNode{ /*边结点定义*/
int adjvex;
struct ArcNode *nextArc;
int weight;
}ArcNode;
typedef struct VNode{ /*顶点定义*/
char data;
ArcNode *firstArc;
}VNode, AdjList[MAX_VERTEXT_NUM];
typedef struct{ /*图定义*/
AdjList verTices;
int vexNum;
int arcNum;
int kind;
indegree Indegree;
}ALGraph;
/*建立有向图G 的邻接表存储*/
void CreateGraph(ALGraph *G)
{
int i,j,k,weight;
ArcNode *arcNode;
printf("请输入顶点数和边数:");
scanf("%d %d",&G->vexNum,&G->arcNum);
//建立顶点表
for (i = 0; i < G->vexNum; i++)
{
printf_s("请输入第%d个顶点:", i);
cin>>G->verTices[i].data;
arcNode = (ArcNode *)malloc(sizeof(ArcNode));
arcNode->adjvex=NULL;
arcNode->nextArc=NULL;
G->verTices[i].firstArc=arcNode;
图的邻接表存储与访问
最新推荐文章于 2022-09-20 16:58:35 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)