File tree Expand file tree Collapse file tree 1 file changed +5
-0
lines changed Expand file tree Collapse file tree 1 file changed +5
-0
lines changed Original file line number Diff line number Diff line change @@ -93,17 +93,22 @@ var dijstra = function () {
9393 var tempDistance = 0 ;
9494 init ( src , graph ) ;
9595 while ( current . node != dest && current . distance != Infinity ) {
96+ var changed = false ;
9697 for ( var i = 0 ; i < graph . length ; i += 1 ) {
9798 if ( current . node !== i && //if it's not the current node
9899 ! visited [ i ] && //and if we haven't visited this node
99100 Number . isFinite ( graph [ i ] [ current . node ] ) ) { //and this node is sibling of the current...
100101
101102 tempDistance = current . distance + graph [ i ] [ current . node ] ;
102103 if ( tempDistance < distance [ i ] . distance ) {
104+ changed = true ;
103105 distance [ i ] . distance = tempDistance ;
104106 }
105107 }
106108 }
109+ if ( changed ) {
110+ // TODO the heap should update the order of the elements!
111+ }
107112 visited [ current . node ] = true ;
108113 current = unvisited . extract ( ) ;
109114 }
You can’t perform that action at this time.
0 commit comments