We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f85fd64 commit c26a75eCopy full SHA for c26a75e
1 file changed
src/data-structures/graph/Graph.js
@@ -144,14 +144,19 @@ export default class Graph {
144
*/
145
reverse() {
146
/** @param {GraphEdge} edge */
147
+ const reversedEdges = [];
148
this.getAllEdges().forEach((edge) => {
149
// Delete straight edge from graph and from vertices.
150
this.deleteEdge(edge);
151
152
// Reverse the edge.
153
edge.reverse();
154
- // Add reversed edge back to the graph and its vertices.
155
+ // Add reversed edge to the list of reversed edges.
156
+ reversedEdges.push(edge);
157
+ });
158
+ reversedEdges.forEach((edge) => {
159
+ // Add reversed edge to the graph.
160
this.addEdge(edge);
161
});
162
0 commit comments