Example 1 — Directed versus undirected edges
The same edge 0 to 1 stored both ways.
#include <stdio.h>
int main(void) {
int dir[3][3] = {{0}}, und[3][3] = {{0}};
dir[0][1] = 1;
dir[1][2] = 1;
und[0][1] = und[1][0] = 1;
printf("directed: 0->1=%d, 1->0=%d\n", dir[0][1], dir[1][0]);
printf("undirected: 0-1=%d, 1-0=%d\n", und[0][1], und[1][0]);
int out1 = 0, in1 = 0;
for (int v = 0; v < 3; v++) { out1 += dir[1][v]; in1 += dir[v][1]; }
printf("vertex 1: out-degree=%d in-degree=%d\n", out1, in1);
return 0;
} How It Works
- The directed edge exists only from 0 to 1.
- The undirected edge sets both matrix cells.
- Vertex 1 has one edge leaving (to 2) and one arriving (from 0).
