Skip to content

Commit fd822d2

Browse files
committed
Update formatting in Prim's algorithm
1 parent ade43d9 commit fd822d2

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/graphs/spanning-trees/prim.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* edges.push(new Edge(new Vertex(5), new Vertex(6), 2));
2525
* edges.push(new Edge(new Vertex(6), new Vertex(8), 6));
2626
* edges.push(new Edge(new Vertex(8), new Vertex(7), 7));
27-
* graph = new Graph(edges, 9);
27+
* graph = new Graph(edges, edges.length);
2828
*
2929
* // { edges:
3030
* // [ { e: '1', v: 0, distance: 4 },
@@ -53,9 +53,9 @@
5353
* @public
5454
* @param {Number} id Id of the vertex.
5555
*/
56-
exports.Vertex = function(id) {
56+
exports.Vertex = function (id) {
5757
this.id = id;
58-
}
58+
};
5959

6060
/**
6161
* Graph edge.
@@ -66,11 +66,11 @@
6666
* @param {Vertex} v Vertex which this edge connects.
6767
* @param {Number} distance Weight of the edge.
6868
*/
69-
exports.Edge = function(e, v, distance) {
69+
exports.Edge = function (e, v, distance) {
7070
this.e = e;
7171
this.v = v;
7272
this.distance = distance;
73-
}
73+
};
7474

7575
/**
7676
* Graph.
@@ -80,10 +80,10 @@
8080
* @param {Array} edges Array with graph edges.
8181
* @param {Number} nodesCount Number of nodes in graph.
8282
*/
83-
exports.Graph = function(edges, nodesCount) {
83+
exports.Graph = function (edges, nodesCount) {
8484
this.edges = edges || [];
8585
this.nodesCount = nodesCount || 0;
86-
}
86+
};
8787

8888
/**
8989
* Executes Prim's algorithm and returns minimum spanning tree.
@@ -110,8 +110,9 @@
110110
* @private
111111
* @param {Vertex} a First operand of the comparition.
112112
* @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.
115116
*/
116117
function compareEdges(a, b) {
117118
return b.distance - a.distance;
@@ -168,7 +169,8 @@
168169
});
169170
}
170171
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]));
172174
}
173175
return new exports.Graph(spannigTree);
174176
};

0 commit comments

Comments
 (0)