queue-adt
Queue ADT for browser and nodejs
The Queue class represents a first-in-first-out (FIFO) queue of generic items. It supports the usual enqueue and dequeue operations, along with methods for examining the front of the queue, testing if the queue is empty, and iterating through the items in FIFO order.
Install
Download the production version or the development version.
$ npm install --save queue-adt
$ bower install --save queue-adt
Usage
var Queue = ;var queue = ; queue;queue;queue;queue;queue;queuehello; // Outputs "world"queue;queue; // Outputs "world"queuesize;queue;queuesize; var itr = queueiterator; whileitr console; queue;
<script type="text/javascript" src="https://raw.githubusercontent.com/pasangsherpa/queue-adt/master/dist/queue-adt.min.js"></script><script type="text/javascript"> var queue = ; queue; queue; queue; queue; queue; queuehello; // Outputs "world" queue; queue; // Outputs "world" queuesize; queue; queuesize; var itr = queueiterator; whileitr console; queue;</script>
Documentation
Queue()
Creates an empty queue with infinite capacity.
Queue(initialCapacity)
Creates an empty queue using the specified capacity.
initialCapacity
Type: int
initialCapacity represents the specified capacity.
Methods
throws "Queue is full" error
.enqueue(element) Adds an element to the rear of the queue and returns the new size of the queue.
element
Type: object
the element to be added to the queue.
throws "Queue is empty" error
.dequeue() Removes an element from the front of the queue and returns the element.
Type: object
the element removed from the front of the queue.
throws "Queue is empty" error
.first() Returns without removing the element at the front of the queue.
Type: object
the element at the front of the queue.
.isEmpty()
Returns true if this queue contains no elements.
Type: boolean
whether or not the queue is empty.
.size()
Returns the number of elements in the queue.
Type: int
the number of element in the queue.
.empty()
Removes all element from the the queue and returns the new size of the queue.
.iterator
Returns an iterator to the queue that iterates through the items in FIFO order.
Type: object
the iterator object of the queue
throws "No such element" error
.iterator.next() Returns the next item in FIFO order.
.iterator.hasNext()
Returns whether the queue has next item in FIFO order.