将无向图的邻接矩阵转化为邻接表

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;
			}
		}
}

 

你可能感兴趣的:(数据结构刷题,图,邻接矩阵,邻接表,844真题)