本文图片及数据
对于链式前向星来说是这样的:
看一下链式前向星的代码:
const int maxn = 10005; //点的最大个数 int head[maxn], cnt=0;//head用来表示以i为起点的第一条边存储的位置,cnt读入边的计数器 struct Edge { int next; //同一起点的上一条边的储存位置 int to; //第i条边的终点 int w; //第i条边权重 }; Edge edge[maxn]; void add(int u,int v,int w) //读入边 { edge[cnt].w = w; edge[cnt].to = v; edge[cnt].next = head[u]; head[u] = cnt++; } void read() //遍历所有边 { for(int i=0; i<=n; i++) for(int j=head[i]; j!=-1; j=edge[j].next) }
如有理解不对的地方,希望可以告诉我。
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/231820.html原文链接:https://javaforall.net
