Add edge between 2 existing vertices
self reference
const g = new Graph();g.addVertex("a").addVertex("b");g.addEdge("a", "b");// or const g = new Graph(false, true);g.addVertex("a").addVertex("b");g.addEdge("a", "b", 5);
only pass a value if the isWeighted flag is true
Add a new vertex to the graph
const g = new Graph();g.addVertex("a").addVertex("b");
retrieve the neighbors of a vertex
const g = new Graph();g.addVertex("a").addVertex("b");g.addEdge("a", "b");g.getNeighbors("a"); // {b:1}
Get the current number of vertices in the graph
const g = new Graph();g.addVertex("a").addVertex("b");g.getVerticesNumbers(); //2
Remove edge between 2 vertices if the graph is directional it will remove 1 way
const g = new Graph();g.addVertex("a").addVertex("b");g.addEdge("a", "b");g.removeEdge("a", "b")
Remove a vertex from the graph with all of it's links with other vertices
const g = new Graph();g.addVertex("a").addVertex("b");g.addEdge("a", "b");g.removeVertex("a");
Prints a visual representation of the graph
const g = new Graph();g.addVertex("a").addVertex("b");g.addEdge("a", "b");g.view();// a => [b, 1] :// b => [a, 1] :
Generated using TypeDoc
Add edge between 2 existing vertices
Returns
self reference
Example