无向图邻接表改为邻接矩阵

#include 
#include 
#include 

int a[100][100];//邻接矩阵的载体 

typedef struct ArcNode{
	int adjvex;
	struct ArcNode *nextarc;
}ArcNode; //表结点 

typedef struct VNode{
	char data;
	ArcNode *firstarc;	
}VNode,AdjList[20];//头结点 

typedef struct{
	AdjList vertices;
	int vexnum,arcnum;
}ALGraph;//邻接表 

int LocateVex(ALGraph G,char e)
{
	int i;
	
	for(i=0;iadjvex=j;
		s->nextarc=NULL;
		p=G.vertices[i].firstarc;
		if(!p)
		{
			G.vertices[i].firstarc = s;
		}
		else
		{
			while(p->nextarc)
				p=p->nextarc;
			p->nextarc=s;
		}
		tmp=i;
		i=j;
		j=tmp;
		s= (ArcNode *)malloc(sizeof(ArcNode));
		s->adjvex=j;
		s->nextarc=NULL;
		p=G.vertices[i].firstarc;
		if(!p)
		{
			G.vertices[i].firstarc = s;
		}
		else
		{
			while(p->nextarc)
				p=p->nextarc;
			p->nextarc=s;
		}
	}
}//CreateAdiMatrix

void trans(ALGraph G)
{//转换函数 
	int i,j;
	ArcNode *p;
	
	for(i=0;i<=G.vexnum;i++)//先初始化,全部赋值为0 
		for(j=0;j<=G.vexnum;j++)
		{
			a[i][j]=0;
		}
	for(i=0;iadjvex]=1;
			p=p->nextarc;
		}
	}
}

void Output(ALGraph &G)
{
	int i,j;
	
	for(i=0;i

你可能感兴趣的:(数据结构)