I want to put in a adjacency matrix the following graph:

The left figure is a node link representation of an 8 node network. The right one is an adjacency matrix representation of the same network. The number of
grey cells is equal to the number of links in the graph.
So I want to make a static assigned adjacency matrix. What would be the best approach in C language?
I was thinking something like:
int Matrix[8][8];
and then assign a 1 if the node is connected to other node and 0 if it is not. Also I was thinking to keep a counter for the number of neighbours a node has, like A has 2, B has 3…
But all this I want to be static not dynamic.
In C99, use
enumand ‘designated initializers’:This is a direct transcription of the table you provide; I’ve not verified the table against the graph. The elements without an explicit initializer are zeroed, of course. You could decide to align the close braces, though it isn’t necessary; I quite possibly would.
If you don’t have C99 support available, you are left with manually populating the 2D array:
If you have the graphs presented in some text form, you could write a Perl, Python, or Awk script (to name but three suitable languages) to generate the output for you automatically.
Note: if you want to keep a counter of the number of neighbours that an element has (meaning, I assume, the number of neighbours that can be reached from this node, rather than the number of neighbours that can reach this node – or arrows out rather than arrows in), then you need a more complex structure than a simple 2D array. You’d probably use an array of structures:
I’m not at all convinced that the savings compared with computing the number of arrows out of (or into) a node warrants the extra complexity. Notationally, when referencing elements of the array, you’d now have to write:
instead of the simpler: