将无向图的邻接矩阵转化为邻接表
原创typedef struct
{
int vertex[max];
int arc[max][max];
int vexnum,aecnum;
}MGraph;
typedef struct ArcNode{
int adjvex;
struct ArcNode *next;
}ArcNode;
typedef struct VNode
{
int data;
ArcNode *first;
}VNode,AdjList[max];
typedef struct
{
AdjList vertices;
int vexnum.arcnum;
}ALGraph;
void MtoAL(MGraph G1,ALGraph G2)
{
int i,j;
ArcNode *p;
for(i=0;ivertices[i].first=NULL;
for(i=0;idata=j;
p->next=G2->vertices[i].first;
G2->vertices[i].first=p;
p=(ArcNode *)malloc(sizeof(ArcNode));
p->data=i;
p->next=G2->vertices[j].first;
G2->vertices[j].first=p;
}
}
}
版权声明
所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除