Tarjan: Difference between revisions
Content added Content deleted
(→{{header|zkl}}: added code) |
m (→{{header|zkl}}: tweak) |
||
Line 90:
const INDEX=0, LOW_LINK=1, ON_STACK=2;
fcn init(graph){
▲ var index=0, stack=List(), components=List();
// convert graph to ( (index,lowlink,onStack),(id,links)), ...)
// sorted by id
▲ var G=graph.pump(List.createLong(graph.len()),
foreach v in
foreach v in (G){ if(v[0][INDEX]==Void) strongConnect(v) }
Line 137 ⟶ 136:
<lang zkl> // graph from https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm
// with vertices id zero based (vs 1 based in article)
// ids start at zero and are consecutive (no holes), graph is unsorted
graph:= // ( (id, links/Edges), ...)
T( T(0,1), T(2,0), T(5,2,6), T(6,5),
|