18 lines
395 B
JavaScript
18 lines
395 B
JavaScript
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; |