namastey-circular-queue

1.0.1 • Public • Published

namastey-circular-queue

Description

namastey-circular-queue is a JavaScript package that implements the Circular Queue data structure with various important methods. A Circular Queue is a linear data structure that follows the FIFO (First In First Out) principle and connects the end of the queue back to the beginning, making it circular.

Features

  • enqueue(item): Adds an item to the end of the queue. Throws an error if the queue is full.
  • dequeue(): Removes and returns the item at the front of the queue. Throws an error if the queue is empty.
  • peek(): Returns the item at the front of the queue without removing it. Throws an error if the queue is empty.
  • isEmpty(): Checks if the queue is empty.
  • isFull(): Checks if the queue is full.
  • getSize(): Returns the current number of items in the queue.
  • printQueue(): Prints the queue, showing the elements and null for empty slots.

Installation

To install the package globally, use the following command:

npm install -g namastey-circular-queue

Examples

const CircularQueue = require('namastey-circular-queue');

const queue = new CircularQueue(5);

queue.enqueue(1);
queue.enqueue(2);
queue.enqueue(3);
queue.enqueue(4);
queue.enqueue(5);

console.log(queue.peek()); // Output: 1

queue.printQueue(); // Output: 1 2 3 4 5 

queue.dequeue();
console.log(queue.peek()); // Output: 2

queue.enqueue(6);
queue.printQueue(); // Output: 6 2 3 4 5

Package Sidebar

Install

npm i namastey-circular-queue

Weekly Downloads

3

Version

1.0.1

License

ISC

Unpacked Size

3.59 kB

Total Files

3

Last publish

Collaborators

  • namasteyduniya