我试图用这个逻辑来理解邻接矩阵发生了什么,但我很困惑它所说的关于 abcd 的间隔......
谁能解释这里发生了什么?
谢谢(标记为 java 作为它向我们展示的语言,所以如果有人发布任何代码示例,他们可以看到它是用该语言编写的)
http://compprog.wordpress.com/2007/11/15/all-sources-shortest-path-the-floyd-warshall-algorithm/
这是代码:
for (k = 0; k < n; ++k) {
for (i = 0; i < n; ++i)
for (j = 0; j < n; ++j)
/* If i and j are different nodes and if
the paths between i and k and between
k and j exist, do */
if ((dist[i][k] * dist[k][j] != 0) && (i != j))
/* See if you can't get a shorter path
between i and j by interspacing
k somewhere along the current
path */
if ((dist[i][k] + dist[k][j] < dist[i][j]) ||
(dist[i][j] == 0))
dist[i][j] = dist[i][k] + dist[k][j];