@@ -13,17 +13,17 @@ import { MinHeap, PriorityQueue } from '../data_structures/heap/heap';
1313export const dijkstra = ( graph : [ number , number ] [ ] [ ] , start : number ) : number [ ] => {
1414 // We use a priority queue to make sure we always visit the closest node. The
1515 // queue makes comparisons based on path weights.
16- let priorityQueue = new PriorityQueue ( ( a : [ number , number ] ) => { return a [ 0 ] } , graph . length , ( a : [ number , number ] , b : [ number , number ] ) => { return a [ 1 ] < b [ 1 ] } ) ;
16+ const priorityQueue = new PriorityQueue ( ( a : [ number , number ] ) => { return a [ 0 ] } , graph . length , ( a : [ number , number ] , b : [ number , number ] ) => { return a [ 1 ] < b [ 1 ] } ) ;
1717 priorityQueue . insert ( [ start , 0 ] ) ;
1818 // We save the shortest distance to each node in `distances`. If a node is
1919 // unreachable from the start node, its distance is Infinity.
20- let distances = Array ( graph . length ) . fill ( Infinity ) ;
20+ const distances = Array ( graph . length ) . fill ( Infinity ) ;
2121 distances [ start ] = 0 ;
2222
2323 while ( priorityQueue . size ( ) > 0 ) {
2424 const [ node , _ ] = priorityQueue . extract ( ) ;
2525 graph [ node ] . forEach ( ( [ child , weight ] ) => {
26- let new_distance = distances [ node ] + weight ;
26+ const new_distance = distances [ node ] + weight ;
2727 if ( new_distance < distances [ child ] ) {
2828 // Found a new shortest path to child node. Record its distance and add child to the queue.
2929 // If the child already exists in the queue, the priority will be updated. This will make sure the queue will be at most size V (number of vertices).
0 commit comments