Kosaraju: Difference between revisions

J
(draft description of the task example based on some current implementations)
(J)
Line 365:
[0 0 0 3 3 5 5 7]
</pre>
 
=={{header|J}}==
 
Implementation:
<lang J>visit=: {{
if.y{unvisited do.
unvisited=: 0 y} unvisited
visit y{::out
L=: y,L
end.
}}"0
 
assign=: {{
if._1=y{assigned do.
assigned=: x y} assigned
x&assign y{::in
end.
}}"0
 
kosaraju=: {{
out=: y
in=: <@I.|:y e.S:0~i.#y
unvisited=: 1#~#y
assigned=: _1#~#y
L=: i.0
visit"0 i.#y
assign~L
assigned
}}</lang>
 
Task example:
 
<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>
 
=={{header|Java}}==
6,962

edits