Dijkstra's algorithm: Difference between revisions

Added PicoLisp
m (→‎{{header|Go}}: directed graph)
(Added PicoLisp)
Line 993:
dist
};</lang>
 
=={{header|PicoLisp}}==
<lang PicoLisp>(de neighbor (X Y Cost)
(push (prop X 'neighbors) (cons Y Cost))
(push (prop Y 'neighbors) (cons X Cost)) )
 
(de dijkstra (Curr Dest)
(let Cost 0
(until (== Curr Dest)
(let (Min T Next)
(for N (; Curr neighbors)
(with (car N)
(let D (+ Cost (cdr N))
(unless (and (: distance) (>= D @))
(=: distance D) ) )
(when (> Min (: distance))
(setq Min (: distance) Next This) )
(del (asoq Curr (: neighbors)) (:: neighbors)) ) )
(setq Curr Next Cost Min) ) )
Cost ) )</lang>
Test:
<lang PicoLisp>(neighbor 'a 'b 7)
(neighbor 'a 'c 9)
(neighbor 'a 'f 14)
(neighbor 'b 'c 10)
(neighbor 'b 'd 15)
(neighbor 'c 'd 11)
(neighbor 'c 'f 2)
(neighbor 'd 'e 6)
(neighbor 'e 'f 9)
 
(dijkstra 'a 'e)</lang>
Output:
<pre>-> 20</pre>
 
=={{header|Ruby}}==
Anonymous user