1.0.0 • Published 11 months ago

namastey-adjacency-matrix v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
11 months ago

namastey-adjacency-matrix

Brief Description

namastey-adjacency-matrix is a JavaScript package that implements an adjacency matrix data structure. It provides methods for adding, removing, and checking edges, as well as retrieving and printing the matrix.

Features

  • addEdge(node1, node2): Adds an edge between two nodes. This method updates the matrix to reflect a connection between the nodes.
  • removeEdge(node1, node2): Removes an edge between two nodes. This method updates the matrix to remove the connection between the nodes.
  • hasEdge(node1, node2): Checks if there is an edge between two nodes. Returns true if an edge exists, otherwise false.
  • getMatrix(): Returns the adjacency matrix as a 2D array.
  • printMatrix(): Prints the adjacency matrix to the console.

Installation

To install namastey-adjacency-matrix, run:

npm install -g namastey-adjacency-matrix

Examples

const AdjacencyMatrix = require('namastey-adjacency-matrix');

// Create a new adjacency matrix with 4 nodes
const graph = new AdjacencyMatrix(4);

// Add edges
graph.addEdge(0, 1);
graph.addEdge(1, 2);

// Check if an edge exists
console.log(graph.hasEdge(0, 1)); // Output: true
console.log(graph.hasEdge(0, 2)); // Output: false

// Print the matrix
graph.printMatrix();

// Get the matrix
console.log(graph.getMatrix());