-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathPyConIT FIFOs.c
36 lines (36 loc) · 966 Bytes
/
PyConIT FIFOs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#define TAM 6
int A[TAM][TAM] = {{0, 1, 0, 0, 0, 0},
{0, 0, 1, 0, 0, 0},
{0, 0, 0, 0, 1, 0},
{0, 0, 1, 0, 1, 0},
{1, 0, 0, 0, 0, 0},
{0, 1, 0, 0, 0, 0}};
int *Distancias (int n, int o) {
int *d, x, y;
int *f, s, t;
d = malloc (n * sizeof (int));
for (x = 0; x < n; x++) d[x] = -1;
d[o] = 0;
f = malloc (n * sizeof (int));
s = 0; t = 1; f[s] = o;
while (s < t) {
x = f[s++];
for (y = 0; y < n; y++)
if (A[x][y] == 1 && d[y] == -1) {
d[y] = d[x] + 1;
f[t++] = y;
}
}
free (f);
return d;
}
int main (void) {
int i, j;
int *resultado;
resultado = Distancias (TAM, 3);
printf ("Resultado: ");
for (i = 0; i < 6; i++)
printf ("%d ", resultado[i]);
putchar('\n');
system ("pause");
}