namastey-double-ended-queue
Brief Description
namastey-double-ended-queue
is a JavaScript package that implements a Double-ended Queue (Deque) data structure. It provides methods to efficiently add and remove elements from both ends of the queue.
Features
- addFront(value): Adds an element to the front of the deque.
- addRear(value): Adds an element to the rear of the deque.
- removeFront(): Removes and returns an element from the front of the deque.
- removeRear(): Removes and returns an element from the rear of the deque.
- peekFront(): Peeks at the front element without removing it.
- peekRear(): Peeks at the rear element without removing it.
- isEmpty(): Checks if the deque is empty.
- getSize(): Returns the number of elements in the deque.
Installations
To install the package globally, run:
npm install -g namastey-double-ended-queue
Examples
const Deque = require('namastey-double-ended-queue');
const deque = new Deque();
deque.addFront(10);
deque.addRear(20);
console.log(deque.peekFront());
console.log(deque.peekRear());
deque.addFront(5);
console.log(deque.removeRear());
console.log(deque.removeFront());
console.log(deque.getSize());