mirror of
https://github.com/richardharrington/robotwar.git
synced 2024-06-09 08:29:32 +00:00
removed most comments from Queue.js (easier to read without them)
This commit is contained in:
parent
0afb9164b0
commit
56391578ac
|
@ -11,57 +11,26 @@ http://creativecommons.org/publicdomain/zero/1.0/legalcode
|
|||
|
||||
*/
|
||||
|
||||
/* Creates a new queue. A queue is a first-in-first-out (FIFO) data structure -
|
||||
* items are added to the end of the queue and removed from the front.
|
||||
*/
|
||||
function Queue(){
|
||||
|
||||
// initialise the queue and offset
|
||||
var queue = [];
|
||||
var offset = 0;
|
||||
|
||||
/* Returns the length of the queue.
|
||||
*/
|
||||
this.getLength = function(){
|
||||
|
||||
// return the length of the queue
|
||||
return (queue.length - offset);
|
||||
|
||||
}
|
||||
|
||||
/* Returns true if the queue is empty, and false otherwise.
|
||||
*/
|
||||
this.isEmpty = function(){
|
||||
|
||||
// return whether the queue is empty
|
||||
return (queue.length == 0);
|
||||
|
||||
}
|
||||
|
||||
/* Enqueues the specified item. The parameter is:
|
||||
*
|
||||
* item - the item to enqueue
|
||||
*/
|
||||
this.enqueue = function(item){
|
||||
|
||||
// enqueue the item
|
||||
queue.push(item);
|
||||
|
||||
}
|
||||
|
||||
/* Enqueues multiple items at once.
|
||||
*/
|
||||
|
||||
this.enqueue_array = function(arr) {
|
||||
// enqueue an entire array
|
||||
queue.concat(arr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Dequeues an item and returns it. If the queue is empty then undefined is
|
||||
* returned.
|
||||
*/
|
||||
this.dequeue = function(){
|
||||
|
||||
// if the queue is empty, return undefined
|
||||
|
@ -75,20 +44,12 @@ function Queue(){
|
|||
queue = queue.slice(offset);
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
// return the dequeued item
|
||||
return item;
|
||||
|
||||
}
|
||||
|
||||
/* Returns the item at the front of the queue (without dequeuing it). If the
|
||||
* queue is empty then undefined is returned.
|
||||
*/
|
||||
this.peek = function(){
|
||||
|
||||
// return the item at the front of the queue
|
||||
return (queue.length > 0 ? queue[offset] : undefined);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user