Tarjan: Difference between revisions

m
m (→‎{{header|Wren}}: Minor tidy)
(9 intermediate revisions by 2 users not shown)
Line 13:
;References:
* The article on [[wp:Tarjan's_strongly_connected_components_algorithm|Wikipedia]].
 
See also: [[Kosaraju]]
<br><br>
 
Line 628 ⟶ 630:
 
<syntaxhighlight lang=J>tarjan=: {{
coerase ([ cocurrent) cocreate'' NB. following =: declarations are temporary, expiring when we finish
cocurrent temp=. cocreate''
coerase temp
graph=: y NB. connection matrix of a directed graph
result=: stack=: i.index=: 0
Line 673 ⟶ 674:
 
=={{header|Java}}==
<syntaxhighlight lang="java">
 
<syntaxhighlight>
 
import java.util.ArrayList;
import java.util.HashMap;
Line 889 ⟶ 888:
Results in the zero-base scheme: Array{Int64,1}[[2, 1, 0], [6, 5], [4, 3], [7]]
</pre>
 
=={{header|K}}==
Implementation:
<syntaxhighlight lang=K>F:{[g]
r::s::!i::0
t::+`o`j`k!(#g)#'0,2##g
L::{[g;v]
t[v]:1,i,i; s,:v; i+:1
{[g;v;w]
$[t[`k;w]=#g; L w; ~t[`o;w]; :0N]
t[`j;v]&:t[`j;w]}[g;v]'g v
$[=/t[`j`k;v]
[a:*&v=s; c:a_s; t[`o;c]:0; s::a#s; r,:,c]
]}[g]
{[g;v] $[t[`k;v]=#g; L v; ]}[g]'!#g
r}</syntaxhighlight>
 
Example:
 
<syntaxhighlight lang=K>F (1;2;0;1 2 4;3 5;2 6;5;4 6 7)
(0 1 2
5 6
3 4
,7)</syntaxhighlight>
 
tested with ngn/k
 
=={{header|Kotlin}}==
Line 2,010 ⟶ 2,035:
{{libheader|Wren-seq}}
{{libheader|Wren-dynamic}}
<syntaxhighlight lang="ecmascriptwren">import "./seq" for Stack
import "./dynamic" for Tuple
 
class Node {
9,487

edits