File tree 1 file changed +5
-7
lines changed
1 file changed +5
-7
lines changed Original file line number Diff line number Diff line change 1
- PriorityQueue = () ->
1
+ PriorityQueue = ->
2
2
@_nodes = []
3
3
@ enqueue = (priority , key ) ->
4
4
@_nodes .push
5
5
key : key
6
6
priority : priority
7
7
@ sort ()
8
8
return
9
- @ dequeue = () ->
9
+ @ dequeue = ->
10
10
@_nodes .shift ().key
11
- @ sort = () ->
11
+ @ sort = ->
12
12
@_nodes .sort = (a , b ) ->
13
13
a .priority - b .priority
14
14
return
15
- @ isEmpty = () ->
15
+ @ isEmpty = ->
16
16
! @_nodes .length
17
17
return
18
18
19
19
Graph = ->
20
20
INFINITY = 1 / 0
21
21
@vertices = {}
22
-
23
22
@ addVertex = (name , edges ) ->
24
23
@vertices [name] = edges
25
24
return
26
-
27
25
@ shortestPath = (start , finish ) ->
28
26
nodes = new PriorityQueue
29
27
distances = {}
@@ -91,4 +89,4 @@ g.addVertex 'H',
91
89
E : 1
92
90
F : 3
93
91
94
- console .log g .shortestPath (' A' , ' H' ).concat ([ ' A' ]).reverse ()
92
+ console .log g .shortestPath (' A' , ' H' ).concat ([' A' ]).reverse ()
You can’t perform that action at this time.
0 commit comments