JavaScript实现普通队列(ES5动态原型模式)

队列结构

function Queue() {
    this.items = [];
    if (typeof this.enqueue != 'function') {
        Queue.prototype.enqueue = function(element) {
            this.items.push(element);
        };
        Queue.prototype.dequeue = function(element) {
            return this.items.shift();
        };
        Queue.prototype.front = function(element) {
            return this.items[0];
        };
        Queue.prototype.isEmpty = function(element) {
            return this.length == 0;
        };
        Queue.prototype.size = function(element) {
            return this.items.length;
        };
        Queue.prototype.clear = function(element) {
            this.items = [];
        };
        Queue.prototype.print = function(element) {
            console.log(this.items.toString());
        };
    }
}

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