other-queue

1.0.0 • Public • Published

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() {
  // ..
};

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    1

Package Sidebar

Install

npm i other-queue

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

27 kB

Total Files

13

Last publish

Collaborators

  • ahadb