2

邻接表存储

结构体什么的最优美了

#include <stdio.h>  
#include <string.h>  
  
template<int N,int M>  
struct Graph  
{  
    int top;  
    struct Vertex{  
        int head;  
    }V[N];  
    struct Edge{  
        int v,next;  
    }E[M];  
    void init(){  
        memset(V,-1,sizeof(V));  
        top = 0;  
    }  
    void add_edge(int u,int v){  
        E[top].v = v;  
        E[top].next = V[u].head;  
        V[u].head = top++;  
    }  
};  
  
Graph<1000,10000> g;  
  
int main()  
{  
    return 0;  
}  

来自

nyist_xiaod大佬的博客

posted @ 2017-10-11 17:30  DDYYZZ  阅读(130)  评论(0编辑  收藏  举报