❓ Double-Ended Queue의 약자로, 삽입과 삭제가 양쪽 끝에서 모두 발생할 수 있는 선형 자료 구조
양쪽에서 삽입과 삭제를 할 수 있기 때문에, 다른 자료구조와 달리 데이터 추가 및 삭제가 총 4개 이다.
function Deque(array = []) {
this.array = array;
}
Deque.prototype.getBuffer = function () {
return this.array.slice();
}
Deque.prototype.isEmpty = function () {
return this.array.length === 0;
}
Deque.prototype.pushFront = function (element) {
return this.array.unshift(element);
}
Deque.prototype.popFront = function () {
return this.array.shift();
}
Deque.prototype.pushBack = function (element) {
return this.array.push(element);
}
Deque.prototype.popBack = function () {
return this.array.pop();
}
Deque.prototype.front = function () {
return this.array.length === 0 ? undefined : this.array[0];
}
Deque.prototype.back = function () {
return this.array.length === 0
? undefined
: this.array[this.array.length - 1];
}
Deque.prototype.size = function () {
return this.array.length;
}
Deque.prototype.clear = function () {
this.array = [];
}