Implementation of a queue (...based on arrays) in JavaScript in first-in-first-out order.
git clone https://github.com/ahadb/queue
, create a tarball, or use directly for now
NPM:
npm install another-queue
import Queue from 'other-queue';
const Queue = new Queue();
// ...ß
const queue = new Queue();
Add an element to the queue
const queue = new Queue();
queue.enqueue('i_am_message_1');
queue.enqueue('i_am_message_2');
Dequeue, or remove an element from the queue
const queue = new Queue();
queue.dequeue('i_am_message_1');
See who is next in line
const queue = new Queue();
queue.enqueue('i_am_message_1');
queue.peek();
Get the length of the queue
const queue = new Queue();
queue.getLength()
String representation of queue
const queue = new Queue();
queue.toString()
Check if queue is empty
const queue = new Queue();
queue.isEmpty();
Find a node by value in your Singly Linked List.
Note: you can create your data structures without using arrays as well, or even use my linked-list.
// using plain ole prototype not syntactic class
const Queue = function() {
this.first = null;
this.size = 0;
};
const QueueNode = function(data) {
this.data = data;
this.next = null;
};
Queue.prototype.enqueue = function(data) {
const enqueuedNode = QueueNode(data)
// ..
};
Queue.prototype.dequeue = function() {
// ..
};