Deque
Queueと同様、shiftを自前で実装する必要がある code: Deque.js
class Deque {
constructor() {
this._data = []
this.cur = 0;
this.capacity = 1<<8;
}
get length() {
return this._data.length - this.cur;
}
_fix() {
this._data.splice(0,this.cur);
this.cur = 0;
}
toArray() {
this._fix();
return this._data;
}
push(value) {
this._data.push(value);
while (this.length >= this.capacity) { this.capacity <<= 1; }
}
shift() {
if (this.capacity < this.cur<<1) this._fix();
return ret;
}
pop() {
return this._data.pop();
}
get exist() { return this.length > 0; }
get empty() { return this.length == 0; }
}
手元でのみ確認
Issue
verifyさせる