队列
队列的定义
队列是遵循先进先出原则的一组有序的项。队列在尾部添加新元素,并从头部移除元素。最新添加的元素必须排在队列的末尾
队列的实现
export default function(item) {
this.item = item ? item : [];
this.__proto__.queueIn = function(element) {
this.item.push(element);
};
this.__proto__.queueOut = function() {
return this.item.shift();
};
this.__proto__.peek = function() {
return this.item[0];
};
this.__proto__.isEmpty = function() {
return this.item.length === 0;
};
this.__proto__.size = function() {
return this.item.length;
};
this.__proto__.getQueue = function() {
return this.item;
};
};