-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWarshallAlgorithm-Code
58 lines (49 loc) · 1.57 KB
/
WarshallAlgorithm-Code
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
namespace WarshallAlgorithm
{
class Class1
{
static int Num = 4;
void TransitiveProperty(int[,] graph)
{
int[,] binary_num = new int[Num, Num];
int x, y, z;
for (x = 0; x < Num; x++)
for (y = 0; y < Num; y++)
binary_num[x, y] = graph[x, y];
for (z = 0; z < Num; z++)
{
for (x = 0; x < Num; x++)
{
for (y = 0; y < Num; y++)
{
binary_num[x, y] = (binary_num[x, y] != 0) ||
((binary_num[x, z] != 0) &&
(binary_num[z, y] != 0)) ? 1 : 0;
}
}
}
ReturnMatrix(binary_num);
}
void ReturnMatrix(int[,] binary_num)
{
Console.WriteLine("Transitive" +
" closure of the given graph in Matrix is");
for (int i = 0; i < Num; i++)
{
for (int j = 0; j < Num; j++)
Console.Write(binary_num[i, j] + " ");
Console.WriteLine();
}
}
public static void Main(string[] args)
{
int[,] graph = new int[,]{{0, 1, 0, 1},
{1, 0, 1, 0},
{1, 0, 1, 1},
{0, 0, 0, 1}};
Class1 W = new Class1();
W.TransitiveProperty(graph);
}
}
}