Making an adjacency list in C++ for a directed graph

后端 未结 5 1985
隐瞒了意图╮
隐瞒了意图╮ 2021-01-02 01:19

Hello all :) Today I am refining my skills on graph theory and data structures. I decided to do a small project in C++ because it\'s been a while since I\'ve worked in C++

5条回答
  •  囚心锁ツ
    2021-01-02 01:19

    I would recommend the more general and simple approach of using vector and pairs: #include #include

    typedef std::pair ii; /* the first int is for the data, and the second is for the weight of the Edge - Mostly usable for Dijkstra */
    typedef std::vector vii;
    typedef std::vector  WeightedAdjList; /* Usable for Dijkstra -for example */
    typedef std::vector AdjList; /*use this one for DFS/BFS */
    

    Or alias style (>=C++11):

    using ii = std::pair;
    using vii = std::vector;
    using vi = std::vector;
    using WeightedAdjList = std::vector;
    using AdjList = std::vector;
    

    From here: using vector and pairs (from tejas's answer)

    For additional information you can refer to a very good summary of topcoder: Power up c++ with STL

提交回复
热议问题