function Stack(array) {
this.array = array ? array : [];
}
생성자 함수로 초기 데이터 설정
Stack.prototype.getBuffer = function () {
return this.array.slice();
};
객체 내 데이터 셋 반환
Stack.prototype.isEmpty = function () {
return this.array.length === 0;
};
객체 내 데이터 존재 여부 확인
Stack.prototype.push = function (element) {
return this.array.push(element);
};
데이터 추가
Stack.prototype.pop = function () {
return this.array.pop();
};
데이터 삭제
Stack.prototype.peek = function () {
return this.array[this.array.length - 1];
};
가장 끝 데이터 반환
Stack.prototype.size = function () {
return this.array.length;
};
스택 내 데이터 개수 확인
Stack.prototype.indexOf = function (element, position = 0) {
// return this.array.indexOf(element, position);
for (let i = position; i < this.array.length; i++) {
if (element === this.array[i]) return i;
}
return -1;
};
매개변수로 넘어온 값의 위치 확인
Stack.prototype.includes = function (element, position = 0) {
// return this.array.includes(element);
for (let i = position; i < this.array.length; i++) {
if (element === this.array[i]) return true;
}
return false;
};
데이터 존재 여부 확인