IloveGoodness's blog

By IloveGoodness, history, 3 years ago, In English

In C++, Graphs with large number of nodes (N > 3000) can be stored using vectors

vector<int> adjanced_nodes[N];
if (an edge exists between u and w)
{
  adjacent_nodes[u].push_back(w);
  adjacent_nodes[w].push_back(u);
} 

Pascal language doesn't have vectors, Can anyone please tell how we can store graphs in Pascal?

UPD: thanks Rifat83 for the solution

  • Vote: I like it
  • -1
  • Vote: I do not like it

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

In Pascal it is possible define fixed array like:

var adjanced_nodes: array[0..N-1] of integer;

or if array size is not known at the time of compilation then it is possible to use dynamic arrays, e.g. in FreePascal like:

var adjanced_nodes: array of integer;
begin
  ...
  SetLength(adjanced_nodes, N);
  ...
end.