数据结构 - 队列


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('\n');
}

Queue.prototype.isEmpty = function() {
    return this.data.length === 0;
}

Queue.prototype.getLength = function() {
    return this.data.length;
}

var myQueue = new Queue();

你可能感兴趣的:(数据结构 - 队列)