Kosaraju: Difference between revisions
m
→{{header|J}}: discard globals created by kosaraju implementation on completion, as they have no external relevance
Thundergnat (talk | contribs) m (Combine Python entries with appropriate works with verbiage) |
m (→{{header|J}}: discard globals created by kosaraju implementation on completion, as they have no external relevance) |
||
Line 487:
Implementation:
<syntaxhighlight lang="j">
coerase([cocurrent)cocreate''
if.y{unvisited do.▼
unvisited=: 0 y} unvisited▼
end.▼
L=: y,L
}}"0▼
▲ end.
▲ }}"0
▲assign=: {{
assign=: {{▼
if._1=y{assigned do.
assigned=: x y} assigned
▲ x&assign y{::in
x&assign y{::in▼
end.
}}"0
out=: y
in=: <@I.|:y e.S:0~i.#y
Line 518 ⟶ 517:
0 0 0 3 3 5 5 7</syntaxhighlight>
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
<syntaxhighlight lang="j">▼
▲assign=: {{
if.-.y e.;assigned do.▼
assigned=: (y,L:0~x{assigned) x} assigned▼
▲ x&assign y{::in
end.▼
}}"0▼
▲<syntaxhighlight lang="j">kosarajud=: {{
coerase([cocurrent)cocreate''
visit=: {{
▲ if.y{unvisited do.
▲ unvisited=: 0 y} unvisited
visit y{::out
L=: y,L
▲ end.
▲ }}"0
assign=: {{
▲ if.-.y e.;assigned do.
▲ assigned=: (y,L:0~x{assigned) x} assigned
x&assign y{::in
end.
}}"0
out=: y
in=: <@I.|:y e.S:0~i.#y
Line 540 ⟶ 544:
}}
┌─────┬┬┬───┬┬───┬┬─┐
│0 2 1│││3 4││5 6││7│
|