Détail du package

namastey-undirected-graph

namasteyduniya16ISC1.0.0

A JavaScript package that implements the Undirected Graph data structure with various important methods.

graph, undirected-graph, data-structure, algorithm

readme

namastey-undirected-graph

Brief Description

namastey-undirected-graph is a JavaScript package that provides an implementation of an undirected graph data structure. It supports various methods for manipulating and querying the graph.

Features

  • addVertex(vertex): Adds a new vertex to the graph. If the vertex already exists, it does nothing.
  • addEdge(vertex1, vertex2): Adds an undirected edge between vertex1 and vertex2. Creates vertices if they do not exist.
  • removeVertex(vertex): Removes a vertex and all its edges from the graph.
  • removeEdge(vertex1, vertex2): Removes the undirected edge between vertex1 and vertex2.
  • hasEdge(vertex1, vertex2): Checks if an edge exists between vertex1 and vertex2.
  • printGraph(): Prints the adjacency list representation of the graph.

Installations

You can install namastey-undirected-graph globally using npm:

npm install -g namastey-undirected-graph

Examples

const Graph = require('namastey-undirected-graph');

const graph = new Graph();

graph.addVertex('A');
graph.addVertex('B');
graph.addEdge('A', 'B');
graph.printGraph(); // Output: A -> B\nB -> A

console.log(graph.hasEdge('A', 'B')); // Output: true

graph.removeEdge('A', 'B');
console.log(graph.hasEdge('A', 'B')); // Output: false

graph.removeVertex('A');
graph.printGraph(); // Output: B -> null