19 this->edges =
new int *[V];
20 for (
int i = 0; i < V; i++) {
21 this->edges[i] =
new int[V];
22 for (
int j = 0; j < V; j++) this->edges[i][j] = INT_MAX;
23 this->edges[i][i] = 0;
28 for (
int i = 0; i < vertexNum; i++) {
35 void addEdge(
int src,
int dst,
int weight) {
36 this->edges[src][dst] = weight;
41void print(
const std::vector<int>& dist,
int V) {
42 cout <<
"\nThe Distance matrix for Floyd - Warshall" <<
endl;
43 for (
int i = 0; i < V; i++) {
44 for (
int j = 0; j < V; j++) {
45 if (dist[i * V + j] != INT_MAX)
46 cout << dist[i * V + j] <<
"\t";
58 std::size_t V =
graph.vertexNum;
59 std::vector<std::vector<int> > dist(V, std::vector<int>(V));
62 for (
int i = 0; i < V; i++)
63 for (
int j = 0; j < V; j++) dist[i][j] =
graph.edges[i][j];
66 for (
int k = 0;
k < V;
k++)
69 for (
int i = 0; i < V; i++)
72 for (
int j = 0; j < V; j++)
75 if (dist[i][k] != INT_MAX && dist[k][j] != INT_MAX &&
76 dist[i][k] + dist[k][j] < dist[i][j])
79 dist[i][j] = dist[i][
k] + dist[
k][j];
82 std::vector<int> dist1d(V * V);
83 for (
int i = 0; i < V; i++)
84 for (
int j = 0; j < V; j++) dist1d[i * V + j] = dist[i][j];
93 cout <<
"Enter number of vertices: ";
95 cout <<
"Enter number of edges: ";
98 for (
int i = 0; i < E; i++) {
99 cout <<
"\nEdge " << i + 1 <<
"\nEnter source: ";
101 cout <<
"Enter destination: ";
103 cout <<
"Enter weight: ";
105 G.addEdge(src, dst, weight);
double k(double x)
Another test function.