So I have a task, to build an adjacency matrix out of a given file. The size of the file is unknown, so the N*N matrix will have to be allocated along the way, dynamically allocating every element along the way.
My question is, how does one dynamically allocate an N * N matrix (array of arrays), where N is unknown? I tried researching how to use calloc or realloc , but with no success, I am still unable to understand the usage of these.
The example input would be:
0 1
0 3
0 4
1 0
1 2
1 6
1 9
2 1
2 3
.
.
.
this way, the number of nodes is unknown to the developer, hence the size of the matrix is also unknown.
The output should look something like this:
0 1 0 1 1 0 0 0 ...
1 0 1 0 0 0 1 0 ...
0 1 0 1 ...
.
.
.
a 1 in matrix[i][j] signals, that i and j are adjacent.