Floyd-Warshall algorithm: Difference between revisions
m
→{{header|J}}
m (→{{header|J}}) |
m (→{{header|J}}) |
||
Line 7:
<lang J>(<. <./ .+/~)^:_</lang>
Example use:
<lang J> graph=: (_#&.>~1+i.6),&>6{.(#~5 4 3 2 1) </. 7 9 _ _3 14 10 15 _ _5 11 _ 2 6 _ 9
graph
_ 7 9 _ _3 14
_ _ 10 15 _ _5
_ _ _ 11 _ 2
_ _ _ _ 6 _
_ _ _ _ _ 9
_ _ _ _ _ _
(<. <./ .+/~)^:_ graph
_ 7 9 20 _3 2
_ _ 10 15 21 _5
_ _ _ 11 17 2
_ _ _ _ 6 15
_ _ _ _ _ 9
_ _ _ _ _ _</lang>
The graph matrix holds the costs of each directed node. Row index is index of starting node. Column index is index of ending node. Unconnected nodes have infinite cost.
=={{header|JavaScript}}==
|