其他分享
首页 > 其他分享> > 无向图邻接表

无向图邻接表

作者:互联网

struct edgenode {
	int adjvex;//邻接顶点下标
	int w;//权值
	edgenode* next;
};
struct vexnode {
	int data;
	edgenode* first;
};
struct graph {
	vexnode list[100];
	int numv, nume;
};
void create(graph* G) {
	int i, j, k;
	cin >> G->nume >> G->numv;
	for (i = 0; i < G->numv; i++) {
		cin >> G->list[i].data;
		G->list[i].first = NULL;
	}

	edgenode* e;
	for (k = 0; k < G->nume; k++) {
		cin >> i >> j;
		e = new edgenode;
		//头插法
		e->adjvex = j;
		e->next = G->list[i].first;
		G->list[i].first = e;

		e = new edgenode;
		e->adjvex = i;//无向图
		e->next = G->list[j].first;
		G->list[j].first = e;
	}
}

标签:struct,edgenode,int,list,next,无向,邻接,first
来源: https://www.cnblogs.com/wxy214/p/16485983.html