\begin{algorithm}
\begin{algorithmic}
\FUNCTION{Dijkstra}{\UPPERCASE{$G$}, $s, t$}
\STATE $left \gets $ List()
\FORALL { $n \in $ \call{V}{\UPPERCASE{$G$}} }
\STATE $n.dist \gets \infty$
\STATE $n.parent \gets null$
\STATE \CALL{Add}{$left, n$}
\ENDFOR
\STATE
\STATE $s.dist = 0$
\STATE
\WHILE{\CALL{Length}{$left$} $\neq$ 0}
\STATE $current \gets $ \Call{MinDist}{$left$}\COMMENT{Node with minimal distance.}
\STATE \CALL{Remove}{$left, current$}
\STATE
\IF {$current = t$}
\RETURN{$t$}
\ENDIF
\STATE
\FORALL { $n \in $ \call{Adjacent}{\UPPERCASE{$G$}, $current$} }
\STATE $new\_dist = current.dist $ + \CALL{W}{$current, n$}
\STATE
\IF { $new\_dist < n.dist$ }\COMMENT{Relaxation of $(current, n)$.}
\STATE $n.dist = new\_dist$
\STATE $n.parent = current$
\ENDIF
\ENDFOR
\ENDWHILE
\ENDFUNCTION
\end{algorithmic}
\end{algorithm}
function Dijkstra(G, s, t) {
let left = [];
G.nodes.forEach(function(node) {
node.dist = Infinity;
node.parent = null;
left.push(node);
});
s.dist = 0;
while(left.length !== 0) {
left.sort((a, b) => (a.dist - b.dist));
let current = left.shift();
if (current.equals(t)) {
return t;
}
let adjacent = G.getAdjacentNodes(current);
adjacent.forEach(function(node) {
let newDist = current.dist + W(current, node);
if (newDist < node.dist) {
node.dist = newDist;
node.parent = current;
}
});
}
}