TheAlgorithms-C/data_structures/graphs/transitive_closure.c
meenal2000 aef9d8d53f
fix: file names modified for better readability (#770)
* file names modified

* files name modified

* file names modified

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-11-03 18:46:26 -06:00

61 lines
2.1 KiB
C

#include <stdbool.h>
#include <stdio.h>
#define NODES 4
int digraph[NODES][NODES] = {
{0, 1, 1, 1}, {1, 0, 1, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}};
int tc[NODES][NODES];
void warshall()
{
int i, s, t;
for (s = 0; s < NODES; s++)
for (t = 0; t < NODES; t++) tc[s][t] = digraph[s][t];
for (i = 0; i < NODES; i++)
for (s = 0; s < NODES; s++)
for (t = 0; t < NODES; t++)
if (tc[s][i] && tc[i][t])
tc[s][t] = 1;
}
int main(void)
{
warshall();
int i, j;
for (i = 0; i < NODES; i++)
{
for (j = 0; j < NODES; j++)
{
printf("%d ", tc[i][j]);
}
putchar('\n');
}
return 0;
}
// By
// .----------------. .----------------. .----------------.
// .-----------------. .----------------. .----------------.
// | .--------------. || .--------------. || .--------------. ||
// .--------------. | | .--------------. || .--------------. | | | _________ |
// || | _____ _____ | || | __ | || | ____ _____ | | | | ____ ____
// | || | ____ | | | | | _ _ | | || ||_ _||_ _|| || | / \
// | || ||_ \|_ _| | | | | |_ || _| | || | .' `. | | | | |_/ | |
// \_| | || | | | | | | || | / /\ \ | || | | \ | | | | | | |
// |__| | | || | / .--. \ | | | | | | | || | | ' ' | | || |
// / ____ \ | || | | |\ \| | | | | | | __ | | || | | | | | | |
// | | _| |_ | || | \ `--' / | || | _/ / \ \_ | || | _| |_\ |_
// | | | | _| | | |_ | || | \ `--' / | | | | |_____| | || | `.__.'
// | || ||____| |____|| || ||_____|\____| | | | | |____||____| | || | `.____.'
// | | | | | || | | || | | || | | | | |
// | || | | | | '--------------' || '--------------' ||
// '--------------' || '--------------' | | '--------------' || '--------------'
// |
// '----------------' '----------------' '----------------'
// '----------------' '----------------' '----------------'
// Email : z5261243@unsw.edu.au
// hhoanhtuann@gmail.com