数据结构:链式前向星

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_36225321/article/details/79092836

链式前向星是一种类似邻接表,采用静态数组模拟链表的数据结构

一、建立边结构体:

struct Edge
{
	int to, cost, next
}edge[maxn];

建立数组head[]:head[i]存储以i为起点的第一条边的位置
开始时应初始化为-1

二、添加边函数:

void add(int from, int to, int cost)
{
	edge[count].to = to;
	edge[count].cost = cost;
	edge[count].next = head[from];
	head[from] = count++;
}

三、遍历以v为起点的边

for(int i = head[st];  i != -1; i = edge[i].next)

猜你喜欢

转载自blog.csdn.net/qq_36225321/article/details/79092836