其他分享
首页 > 其他分享> > 图

作者:互联网

图的思维导图

重要概念

图的定义

图的基本术语

图的基本算法

void CreateAdj(AdjGreph * &G, int A[MAXV][MAXV], int n, int e) {
	int i, j;
	ArcNode* p;
	G = (AdjGraph*)malloc(sizeof(AdjGraph));
	for (i = 0; i < n; i++)
		G->adjlist[i].firstarc = NULL;
	for(i=0;i<n;i++)
		for(j=n-1;j>=0;j--)
			if (A[i][j] != 0 && A[i][j] != INF) {
				p= (ArcNode*)malloc(sizeof(ArcNode));
				p->adjvex = j;
				p->weight = A[i][j];
				p->nextarc = G->adjlist[i].firstarc;
				G->adjlist[i].firstarc = p;
			}
	G->n = n; G->e = e;
}
void DispAdj(AdjGraph* G) {
	int i;
	ArcNode* p;
	for (i = 0; i < G->n; i++) {
		p = G->adjlist[i].firstarc;
		printf("%3d: ", i);
		while (p != NULL) {
			printf("%3d[%d->", p->adjvex, p->weight);
			p = p->nextarc;
		}
		printf("^\n");
	}
}
void DestroyAdj(AdjGraph*& G) {
	int i;
	ArcNode* pre, * p;
	for (i = 0; i < G->n; i++) {
		pre = G->adjlist[i].firstarc;
		if (pre != NULL) {
			p = pre->nextarc;
			while (p != NULL) {
				free(pre);
				pre = p; p = p->nextarc;
			}
			free(pre);
		}
	}
	free(G);
}

图的遍历

typedef struct ANode {
	int i, j;
	struct ANode* nextarc;
}ArcNode;                       //边结点类型
typedef struct Vnode {
	ArcNode* firstarc;          //指向第一个相邻可走方块
}VNode;
typedef struct {
	VNode adjlist[M + 2][N + 2];//头结点数组
}AdjGraph;                      //迷宫图的邻接表类型

构造最小生成树的准则

拓扑排序方法

疑难问题

-Kruskal的堆排序

标签:,pre,adjlist,int,ArcNode,firstarc,顶点
来源: https://www.cnblogs.com/xypeanut/p/14826621.html