Dijkstra's algorithm: Difference between revisions

Line 1,374:
</lang>
{{out}}
<pre>
<pre>((A C D E) 26)</pre>
> (dijkstra-short-pathspath 'a 'e)
<pre>((A C D E) 26)</pre>
</pre>
<lang lisp>
(defvar *r* nil)
Line 1,401 ⟶ 1,404:
(defun nodes (c w)
(sort (cdr (assoc c w)) #'< :key #'cddr))
 
(dijkstra-short-paths
'(a b c d e f)
'((a (a b . 7) (a c . 9) (a f . 14))
(b (b c . 10) (b d . 15))
(c (c d . 11) (c f . 2))
(d (d e . 6))
(e (e f . 9))))
</lang>
{{out}}
<pre>
> (dijkstra-short-paths
'(a b c d e f)
'((a (a b . 7) (a c . 9) (a f . 14))
(b (b c . 10) (b d . 15))
(c (c d . 11) (c f . 2))
(d (d e . 6))
(e (e f . 9))))
Path: (A B) Distance: 7
Path: (A C) Distance: 9
Anonymous user