C++ vector, what does this code mean?

前端 未结 6 1137
谎友^
谎友^ 2021-01-23 22:27

I have this code:

 const int maxnodes = 5000;
 struct Edge 
 {
   int to, rev;
   int f, cap;
 };

 vector g[maxnodes];

This is qui

6条回答
  •  执念已碎
    2021-01-23 23:06

    It is a C-array of vectors

    Example with maxnodes = 5. G[5]

    0 -> std::vector 
    1 -> std::vector 
    2 -> std::vector 
    3 -> std::vector 
    4 -> std::vector 
    

    If each element of g contains 5 elements, it would look like this

    G
    -
    0 -> {0, 1, 2, 3, 4}
    1 -> {0, 1, 2, 3, 4}
    2 -> {0, 1, 2, 3, 4}
    3 -> {0, 1, 2, 3, 4}
    4 -> {0, 1, 2, 3, 4}
    

    Meaning, g[u][j], for example with g[2][3] would correspond to the third element in the vector at the second element of g.

    g[2][3]

    G
    -
    0 -> {0, 1, 2, 3, 4}
    1 -> {0, 1, 2, 3, 4}
    2 -> {0, 1, 2, ***3***, 4}
    3 -> {0, 1, 2, 3, 4}
    4 -> {0, 1, 2, 3, 4}
    

提交回复
热议问题