队列的enqueue方法和dequeue方法添加和移除元素 ,原理是利用array的push()和shift
()实现
完整的Queue类
function Queue() {
var items = [];
this.enqueue = function(element){<br /> items.push(element);
};
this.dequeue = function(){
return items.shift();
};
this.front = function(){
return items[0];
};
this.isEmpty = function(){
return items.length == 0;
};
this.clear = function(){
items = [];
};
this.size = function(){
return items.length;
};
this.print = function(){
console.log(items.toString());
};
}