Spaces:
Running
Running
| /** | |
| * Copyright (c) 2017~2020, OBCon Inc. | |
| * All rights reserved. | |
| */ | |
| /** | |
| * @file | |
| * @copyright 2017~2020, OBCon Inc. | |
| * @author gye hyun james kim [pnuskgh@gmail.com] | |
| */ | |
| class Queue { //--- FIFO (First In First Out) | |
| constructor(data) { | |
| this._maxSize = 0; //--- 0. 크기 제한 없음 | |
| this._data = data || []; | |
| } | |
| get maxSize() { | |
| return this._maxSize; | |
| } | |
| set maxSize(newValue) { | |
| this._maxSize = newValue; | |
| } | |
| getBuffer() { //--- Stack 복사 | |
| return this._data.slice(); | |
| } | |
| isEmpty() { | |
| return this._data.length == 0; | |
| } | |
| peek() { //--- 첫번째 항목 조회 | |
| return (this.isEmpty()) ? null : this._data[0]; | |
| } | |
| enqueue(item) { //--- 항목 추가 | |
| this._data.push(item); | |
| if ((0 < this._maxSize) && (this._maxSize < this._data.length)) { | |
| this._data.slice(); | |
| } | |
| } | |
| dequeue() { //--- 항목 제거 | |
| return this._data.shift(); | |
| } | |
| } | |
| module.exports = Queue; | |