Double-Ended Queue의 약자로, 삽입과 삭제가 양쪽 끝에서 모두 발생할 수 있는 선형 자료 구조
대부분의 메서드는 큐와 동일하나, 앞에서 추가 삭제, 뒤에서 추가 삭제, 첫번째와 끝의 데이터를 반환하는 메서드가 추가됨
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.length === 0 ? undefined : this.array[0];
}
Deque.prototype.back = function() {
return this.length === 0 ? undefined : this.array[this.array.length - 1];
}
Deque.prototype.size = function() {
return this.array.length;
}
Deque.prototype.clear = function() {
this.array = [];
}
관련 전체 코드는 Git에 업로드 해두었습니다.
Github_Deque