namastey-double-ended-queue
v1.0.1
Published
A JavaScript package that implements the Double-ended Queue (Deque) data structure with various important methods for efficient data handling.
Downloads
14
Maintainers
Readme
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()); // Output: 10
console.log(deque.peekRear()); // Output: 20
deque.addFront(5);
console.log(deque.removeRear()); // Output: 20
console.log(deque.removeFront()); // Output: 5
console.log(deque.getSize()); // Output: 1