• 链式前向星


    链式前向星:头插法的静态邻接链表(类似于头插法的邻接链表)

    ①int tot:用于计算边的编号

    ②head[MAX]:用来存储以i为起点的最新加入的边在edge[]中的存储位置

    ③struct Node{ int to; int w; int next}; 

    to表示终点;w是权值;next表示下一条边在edge[]数组中的存储位置

    Node edge[MAX]:用来存储边的信息

    int head[maxn];    //存以i为起点的最近加入的一条边的存储位置 
    int tot;        //边的编号 
    
    struct Node{        //链式前向星 struct
        int to;        //边的终点     
        int w;        //权值 
        int next;    //相同起点的上一次加入的边的存储位置 (指向下一条边在edge数组中的位置)
    }edge[maxn*2];
    
    void init(){
        tot = 0;
        memset(head,-1,sizeof(head));    //将head初始化为-1 
    }
    
    void add_edge(int from, int to, int w){        //from起点, to终点, w权值 
        edge[tot].to=to;
        edge[tot].w=w;
        edge[tot].next=head[from]; //head[from]:上一次加入的边的位置 
        head[from]=tot++;          //更新以from为起点的最新加入的边的编号 
    }
  • 相关阅读:
    统计一行字符串中每个字母个数
    不定宽高的文字在div中垂直居中
    转:Python 与 Excel 不得不说的事
    Centos 6安装python3.5
    day04
    day03
    Day02
    python ciscolib模块
    三级菜单
    模拟登陆系统
  • 原文地址:https://www.cnblogs.com/shiliuxinya/p/12037675.html
Copyright © 2020-2023  润新知