-
Notifications
You must be signed in to change notification settings - Fork 0
/
WashallAlgorithm.cpp
79 lines (70 loc) · 1.37 KB
/
WashallAlgorithm.cpp
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
68
69
70
71
72
73
74
75
76
77
78
79
#include<iostream>
#include<stdlib.h>
using namespace std;
int binaryMatrics[100][100];
void Warshall(int n)
{
int nowBinaryArray[100][100];
for(int k=1;k<=n;k++)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
nowBinaryArray[i][j] = binaryMatrics[i][j] || (binaryMatrics[i][k] && binaryMatrics[k][j]);
}
}
for(int h=1;h<=n;h++)
{
for(int r = 1;r<=n;r++)
{
binaryMatrics[h][r] = nowBinaryArray[h][r];
}
}
}
}
void constructGraph(int n,char str[])
{
int a=0;
while(a <= (n*n))
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{ a++;
if(a==n*n)
return;
if(i!=j){
cout << "If (" << str[i] <<"," << str[j] << ") are connected then Enter 1 else 0 :" ;
cin >> binaryMatrics[i][j];
}
}
}
}
}
void display(int n)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
cout << binaryMatrics[i][j] << " ";
if(j==n)
cout << endl;
}
}
}
int main()
{
char str[100];
int n;
cout << "Enter the number of vertices which is producing non-trivial graph : ";
cin >> n;
for(int i=1;i<=n;i++)
str[i] = 96 + i;
constructGraph(n,str);
Warshall(n);
cout << endl << endl<< "Displaying Warshall algorithm result : " << endl;
display(n);
return 0;
}