首页 > 技术文章 > 算法笔记--图的存储之链式前向星

widsom 2017-10-08 14:34 原文

链式前向星

这个博客写的不错:http://blog.csdn.net/acdreamers/article/details/16902023

模板:

①add_edge

 

void add_edge(int u,int v,int w)
{
        edge[cnt].to=v;
        edge[cnt].w=w;
        edge[cnt].next=head[u];
        head[u]=cnt++;
}

 

②遍历以u节点为起点的所有边

 

for(int i=head[u];~i;i=edge[i].next)

 

推荐阅读