|
24 | 24 | * edges.push(new Edge(new Vertex(5), new Vertex(6), 2)); |
25 | 25 | * edges.push(new Edge(new Vertex(6), new Vertex(8), 6)); |
26 | 26 | * edges.push(new Edge(new Vertex(8), new Vertex(7), 7)); |
27 | | - * graph = new Graph(edges, 9); |
| 27 | + * graph = new Graph(edges, edges.length); |
28 | 28 | * |
29 | 29 | * // { edges: |
30 | 30 | * // [ { e: '1', v: 0, distance: 4 }, |
|
53 | 53 | * @public |
54 | 54 | * @param {Number} id Id of the vertex. |
55 | 55 | */ |
56 | | - exports.Vertex = function(id) { |
| 56 | + exports.Vertex = function (id) { |
57 | 57 | this.id = id; |
58 | | - } |
| 58 | + }; |
59 | 59 |
|
60 | 60 | /** |
61 | 61 | * Graph edge. |
|
66 | 66 | * @param {Vertex} v Vertex which this edge connects. |
67 | 67 | * @param {Number} distance Weight of the edge. |
68 | 68 | */ |
69 | | - exports.Edge = function(e, v, distance) { |
| 69 | + exports.Edge = function (e, v, distance) { |
70 | 70 | this.e = e; |
71 | 71 | this.v = v; |
72 | 72 | this.distance = distance; |
73 | | - } |
| 73 | + }; |
74 | 74 |
|
75 | 75 | /** |
76 | 76 | * Graph. |
|
80 | 80 | * @param {Array} edges Array with graph edges. |
81 | 81 | * @param {Number} nodesCount Number of nodes in graph. |
82 | 82 | */ |
83 | | - exports.Graph = function(edges, nodesCount) { |
| 83 | + exports.Graph = function (edges, nodesCount) { |
84 | 84 | this.edges = edges || []; |
85 | 85 | this.nodesCount = nodesCount || 0; |
86 | | - } |
| 86 | + }; |
87 | 87 |
|
88 | 88 | /** |
89 | 89 | * Executes Prim's algorithm and returns minimum spanning tree. |
|
110 | 110 | * @private |
111 | 111 | * @param {Vertex} a First operand of the comparition. |
112 | 112 | * @param {Vertex} b Second operand of the comparition. |
113 | | - * @return {number} Number which which is equal, greater or less then zero and |
114 | | - * indicates whether the first vertex is "greater" than the second. |
| 113 | + * @return {number} Number which which is equal, greater or |
| 114 | + * less then zero and indicates whether the first vertex is |
| 115 | + * "greater" than the second. |
115 | 116 | */ |
116 | 117 | function compareEdges(a, b) { |
117 | 118 | return b.distance - a.distance; |
|
168 | 169 | }); |
169 | 170 | } |
170 | 171 | for (var node in parents) { |
171 | | - spannigTree.push(new exports.Edge(node, parents[node], distances[node])); |
| 172 | + spannigTree.push( |
| 173 | + new exports.Edge(node, parents[node], distances[node])); |
172 | 174 | } |
173 | 175 | return new exports.Graph(spannigTree); |
174 | 176 | }; |
|
0 commit comments