-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWarshall's Algorithm
67 lines (65 loc) · 1.81 KB
/
Warshall's Algorithm
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
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
int[,] matrixarray = { {0, 1, 0, 0}
,{0, 1, 0, 1},
{0, 0, 1, 1},
{0, 1, 0, 0} };
newclass obj = new newclass();
obj.mat(matrixarray);
Console.ReadLine();
}
}
class newclass
{
public static int rc = 4;
public void mat(int[,] mn)
{
int[,] matrixarray = new int[rc, rc];
for (int i = 0; i < rc; i++)
{
for (int j = 0; j < rc; j++)
{
matrixarray[i, j] = mn[i, j];
}
}
for (int i = 0; i < rc; i++)
{
for (int j = 0; j < rc; j++)
{
for (int k = 0; k < rc; k++)
{
matrixarray[j, k] = (matrixarray[j, k] != 0) || ((matrixarray[i, k] != 0) && (matrixarray[j, i] != 0)) ? 1 : 0;
}
}
}
matrixarrayPrinter(matrixarray);
}
public void matrixarrayPrinter(int[,] mn)
{
for (int i = 0; i < rc; ++i)
{
for (int j = 0; j < rc; ++j)
{
if (mn[i, j] == 99999)
{
Console.Write("\t");
}
else
{
Console.Write(mn[i, j] + "\t");
}
}
Console.WriteLine();
}
}
}
}