データ構造-キュー

548 ワード


var Queue = function() {
    this.data = [];
}

Queue.prototype.enqueue = function(element) {
    this.data.push(element);
}

Queue.prototype.dequeue = function() {
    return this.data.shift();
}

Queue.prototype.peek = function() {
    return this.data[0];
}

Queue.prototype.print = function() {
    return this.data.join('
'); } Queue.prototype.isEmpty = function() { return this.data.length === 0; } Queue.prototype.getLength = function() { return this.data.length; } var myQueue = new Queue();