Skip to content

ahadb/queue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

npm install another-queue

Use

import Queue from 'other-queue';

const Queue = new Queue();
// ...ß

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

About

A queue in JavaScript with a FIFO order

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published