Add Bellman-Ford.

This commit is contained in:
Oleksii Trekhleb
2018-05-03 09:58:00 +03:00
parent c97e472db7
commit 5788575718
8 changed files with 142 additions and 5 deletions

View File

@ -32,6 +32,13 @@ export default class Graph {
return vertex.getNeighbors();
}
/**
* @return {GraphVertex[]}
*/
getAllVertices() {
return Object.values(this.vertices);
}
/**
* @param {GraphEdge} edge
* @returns {Graph}

View File

@ -28,6 +28,10 @@ describe('Graph', () => {
graph.addEdge(edgeAB);
expect(graph.getAllVertices().length).toBe(2);
expect(graph.getAllVertices()[0]).toEqual(vertexA);
expect(graph.getAllVertices()[1]).toEqual(vertexB);
const graphVertexA = graph.findVertexByKey(vertexA.getKey());
const graphVertexB = graph.findVertexByKey(vertexB.getKey());