44 lines
857 B
C
44 lines
857 B
C
#include <stdio.h>
|
|
|
|
#define N 3
|
|
|
|
typedef int Mat[N*N];
|
|
|
|
void matiter(Mat C, int (*reduce)(int old, int ik, int kj)) {
|
|
for(unsigned int k = 0; k < N; k++) {
|
|
for(unsigned int i = 0; i < N; i++) {
|
|
for(unsigned int j = 0; j < N; j++) {
|
|
C[i*N+j] = reduce(C[i*N+j], C[i*N+k], C[k*N+j]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
int floyd(int old, int ik, int kj) {
|
|
int new = ik + kj;
|
|
return ( old < new ? old : new );
|
|
}
|
|
|
|
int warshall(int old, int ik, int kj) {
|
|
return (old ? old : ik && kj);
|
|
}
|
|
|
|
int main( int argc, char *argv[] ) {
|
|
Mat C =
|
|
{
|
|
0 , 0 , 0 ,
|
|
1 , 0 , 0 ,
|
|
0 , 1 , 0
|
|
};
|
|
|
|
matiter(C, *warshall);
|
|
|
|
for(unsigned int i = 0; i < N; i++) {
|
|
for(unsigned int j = 0; j < N; j++) {
|
|
printf("%5d ", C[i*N+j]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
return 0;
|
|
}
|