This repository has been archived by the owner on Oct 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfloydandwarshall.h
122 lines (104 loc) · 2.33 KB
/
floydandwarshall.h
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#ifndef floydandwarshall_h
#define floydandwarshall_h
#include<iostream>
#include <algorithm>
using namespace std;
#define inf 10000
class Graph
{
public:
int n;
int **mat;
Graph()
{
cout<<" Enter Number Of Vertices : ";
cin>>n;
mat = new int*[n];
for(int i = 0; i < n; i++)
{
mat[i] = new int[n];
}
}
int weightmatrix()
{
cout<<"\n\n Creating Weight Matrix \n\n";
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
cout<<" Enter Value ( For Infinity Enter -1) : ";
cin>>mat[i][j];
if(mat[i][j] == -1)mat[i][j] = inf;
}
cout<<"\n";
}
cout<<"\n\n";
return 0;
}
int adjacencymatrix()
{
cout<<"\n\n Creating Adjacency Matrix \n\n";
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
cout<<" Enter Value : ";
cin>>mat[i][j];
}
cout<<"\n";
}
cout<<"\n\n";
return 0;
}
int warshall()
{
int i,j,k;
for(k = 0; k < n; k++)
{
for(j = 0; j < n; j++)
{
for(i = 0; i < n; i++)
{
mat[i][j] = mat[i][j] | (mat[i][k] & mat[k][j]);
}
}
}
cout<<"\n\n Transitive Closure \n\n";
for(i = 0; i < n; i++)
{
for(j = 0; j < n; j++)
{
cout<<" "<<mat[i][j]<<" ";
}
cout<<endl;
}
cout<<"\n\n";
return 0;
}
int floyd()
{
int k, j, i;
for(k = 0; k < n; k++)
{
for(j = 0; j < n; j++)
{
for(i = 0; i < n; i++)
{
mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j]);
}
}
}
cout<<"\n\n Distance Matrix \n\n";
for(i = 0; i < n; i++)
{
for(j = 0; j < n; j++)
{
cout<<" "<<mat[i][j]<<" ";
}
cout<<endl;
}
cout<<"\n\n";
return 0;
}
};
#endif