// Queue
class Queue {
constructor() {
this.collection = [];
}
enqueue(value) {
this.collection.push(value);
}
dequeue() {
return this.collection.shift();
}
front() {
if (this.isEmpty()) {
return null;
}
return this.collection[0];
}
size() {
return this.collection.length;
}
isEmpty() {
return this.collection.length === 0;
}
}
let myQueue = new Queue();
myQueue.enqueue('a');
myQueue.enqueue('b');
myQueue.enqueue('c');
console.log(myQueue);
console.log(myQueue.isEmpty()); // should return false
console.log(myQueue.front());
console.log(myQueue.size()); // should return 3
console.log(myQueue.dequeue());
console.log(myQueue.front()); // should return b
console.log(myQueue.size()); // should return 2
자바스크립트 shift 가 사기다....
대신 좀 무겁겠지....
index 로 하나하나 구현 해 주는게 나을려나...
후.........
큐를 만들어보는거에 의미가있는거 큐를 사용해서 문제풀때 이렇게 큐를 구현해서 풀지는않음 걍 배열쓰지
아닌데? 난 큐 쓰는데?
Js로 제대로된 큐 만들려면 링크드리스트 만들고 큐를 링크드리스트로 구현해야됨 귀찮아
역시 문제풀이는... 다양한 방법으로 접근 가능하다.. 후..........
나도 큐 쓰는데? 큐큐큐