1.0.0 • Published 3 years ago
other-queue v1.0.0
Queue
Implementation of a queue (...based on arrays) in JavaScript in first-in-first-out order.
Install
git clone https://github.com/ahadb/queue
, create a tarball, or use directly for now
NPM:
To be published on NPM soon
Use
To be published on NPM soon
API
Constructor & Instance
const queue = new Queue();
queue.enqueue
Add an element to the queue
const queue = new Queue();
queue.enqueue('i_am_message_1');
queue.enqueue('i_am_message_2');
queue.dequeue
Dequeue, or remove an element from the queue
const queue = new Queue();
queue.dequeue('i_am_message_1');
queue.peek
See who is next in line
const queue = new Queue();
queue.enqueue('i_am_message_1');
queue.peek();
queue.getLength
Get the length of the queue
const queue = new Queue();
queue.getLength()
queue.toString
String representation of queue
const queue = new Queue();
queue.toString()
queue.isEmpty
Check if queue is empty
const queue = new Queue();
queue.isEmpty();
LinkedList.find
Find a node by value in your Singly Linked List.
On Creating Your Own Data Structures
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() {
// ..
};
1.0.0
3 years ago