Kosaraju: Difference between revisions
Content added Content deleted
(J) |
(J) |
||
Line 399: | Line 399: | ||
<lang J> kosaraju 1;2;0;1 2 4;3 5;2 6;5;4 6 7 |
<lang J> kosaraju 1;2;0;1 2 4;3 5;2 6;5;4 6 7 |
||
0 0 0 3 3 5 5 7</lang> |
0 0 0 3 3 5 5 7</lang> |
||
Alternatively, we could represent the result as a graph of the same type as our argument graph. The implementation of <tt>visit</tt> remains the same, and: |
|||
<lang J> |
|||
assign=: {{ |
|||
if.-.y e.;assigned do. |
|||
assigned=: (y,L:0~x{assigned) x} assigned |
|||
x&assign y{::in |
|||
end. |
|||
}}"0 |
|||
kosaraju=: {{ |
|||
out=: y |
|||
in=: <@I.|:y e.S:0~i.#y |
|||
unvisited=: 1#~#y |
|||
assigned=: a:#~#y |
|||
L=: i.0 |
|||
visit"0 i.#y |
|||
assign~L |
|||
assigned |
|||
}} |
|||
kosaraju 1;2;0;1 2 4;3 5;2 6;5;4 6 7 |
|||
┌─────┬┬┬───┬┬───┬┬─┐ |
|||
│0 2 1│││3 4││5 6││7│ |
|||
└─────┴┴┴───┴┴───┴┴─┘ |
|||
</lang> |
|||
=={{header|Java}}== |
=={{header|Java}}== |