Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit88d038b

Browse files
m-maksyutintrekhleb
authored andcommitted
Fix the findEdge method of the graph (trekhleb#80)
* Fix LinkedList* Fix the prepend method for the LinkedList* Fix the remove method for the MinHeap* Correct a comment* Fix BST removal method* Fix the findEdge method of the graph
1 parent89fb0e6 commit88d038b

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

‎src/data-structures/graph/Graph.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ export default class Graph {
115115
*/
116116
findEdge(startVertex,endVertex){
117117
constvertex=this.getVertexByKey(startVertex.getKey());
118+
if(!vertex){
119+
returnnull;
120+
}
118121
returnvertex.findEdge(endVertex);
119122
}
120123

‎src/data-structures/graph/__test__/Graph.test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@ describe('Graph', () => {
8787

8888
constgraphEdgeAB=graph.findEdge(vertexA,vertexB);
8989
constgraphEdgeBA=graph.findEdge(vertexB,vertexA);
90-
constgraphEdgeAC=graph.findEdge(vertexB,vertexC);
90+
constgraphEdgeAC=graph.findEdge(vertexA,vertexC);
91+
constgraphEdgeCA=graph.findEdge(vertexC,vertexA);
9192

9293
expect(graphEdgeAC).toBeNull();
94+
expect(graphEdgeCA).toBeNull();
9395
expect(graphEdgeAB).toEqual(edgeAB);
9496
expect(graphEdgeBA).toEqual(edgeAB);
9597
expect(graphEdgeAB.weight).toBe(10);
@@ -108,9 +110,11 @@ describe('Graph', () => {
108110

109111
constgraphEdgeAB=graph.findEdge(vertexA,vertexB);
110112
constgraphEdgeBA=graph.findEdge(vertexB,vertexA);
111-
constgraphEdgeAC=graph.findEdge(vertexB,vertexC);
113+
constgraphEdgeAC=graph.findEdge(vertexA,vertexC);
114+
constgraphEdgeCA=graph.findEdge(vertexC,vertexA);
112115

113116
expect(graphEdgeAC).toBeNull();
117+
expect(graphEdgeCA).toBeNull();
114118
expect(graphEdgeBA).toBeNull();
115119
expect(graphEdgeAB).toEqual(edgeAB);
116120
expect(graphEdgeAB.weight).toBe(10);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp