代码拉取完成,页面将自动刷新
var MyCircularQueue = function (k) {
this.arr = new Array(k);
this.head = 0;
this.tail = -1;
this.cnt = 0;
};
/**
* @param {number} value
* @return {boolean}
*/
MyCircularQueue.prototype.enQueue = function (value) {
if (this.isFull()) return false;
this.tail += 1;
this.tail %= this.arr.length;
this.arr[this.tail] = value;
this.cnt++;
return true;
};
/**
* @return {boolean}
*/
MyCircularQueue.prototype.deQueue = function () {
if (this.isEmpty()) return false;
this.head += 1;
this.head %= this.arr.length;
this.cnt--;
return true;
};
/**
* @return {number}
*/
MyCircularQueue.prototype.Front = function () {
if (this.isEmpty()) return -1;
return this.arr[this.head];
};
/**
* @return {number}
*/
MyCircularQueue.prototype.Rear = function () {
if (this.isEmpty()) return -1;
return this.arr[this.tail];
};
/**
* @return {boolean}
*/
MyCircularQueue.prototype.isEmpty = function () {
return this.cnt === 0
};
/**
* @return {boolean}
*/
MyCircularQueue.prototype.isFull = function () {
return this.cnt === this.arr.length;
};