dijkstra-backend/helpers/graph.js

18 lines
395 B
JavaScript
Raw Normal View History

2020-02-08 18:59:51 +00:00
class Graph {
constructor() {
this.nodes = [];
this.adjacencyList = {};
}
addNode(node) {
this.nodes.push(node);
this.adjacencyList[node] = [];
}
addEdge(node1, node2, distance) {
this.adjacencyList[node1].push({node:node2, distance});
this.adjacencyList[node2].push({node:node1, distance});
}
}
module.exports = Graph;