JS 코딩테스트

[JS코테] javascript로 큐 구현

Nuri-KSLV-II 2025. 8. 17. 20:11

자바스크립트에서 내장 메소드 사용 x

배열을 이용해 직접 구현 후 사용

 

class Queue {
	items = [];
    front = 0;
    rear = 0;
    
    push(item) {
    	this.items.push(item);
        this.rear++;
    }
    
    pop(){
    	return this.item[this.front++];
    }
    
    isEmpty() {
    	return this.front === this.rear;
    }
}