kingofnumbers's blog

By kingofnumbers, 9 years ago, In English

I want help to explain the behavior of this code

this code reads an undirected graph then store list of the edges in list vector, then in the adj vector I store adjacency list of the graph where I actually store pointers to the edges from list vector

but as you can see there's some random big numbers appear in the output but I don't know how, maybe I am making some undefined behavior some where? , any help would be appreciated.

  • Vote: I like it
  • +5
  • Vote: I do not like it

»
9 years ago, # |
  Vote: I like it +20 Vote: I do not like it

After some push_back operations (for example, when size is a power of 2) the whole vector moves to another place in memory and you keep addresses to wrong old locations of the elements.