% 연산을 통해 front 및 rear 인덱스 계산
ex. front = (front + 1) % max_len;
STRUCTURE
private capacity: number;
private count: number;
private front: number;
private rear: number;
private queue: string[];
FEATURE
enqueue
public enQueue(data: string): boolean {
if (this.isFull())
return false;
this.queue[this.rear] = data;
this.rear = (this.rear + 1) % this.capacity;
this.count++;
return true;
}
dequeue
public deQueue(): string {
const returnData = this.queue[this.front];
this.front = (this.front + 1) % this.capacity;
this.count--;
return returnData;
}
public deQueueSecond(): void {
this.queue[(this.front + 1) % this.capacity] = this.queue[this.front];
this.front = (this.front + 1) % this.capacity;
this.count--;
}
peek
public peek(flag: number): string {
if (flag === 1)
return this.queue[this.front];
return this.queue[(this.front + 1) % this.capacity];
}