队列是一种特殊的线性表,具有先进先出的特性。
在 JavaScript 中,可以使用数组来实现队列。下面是一个简单的队列类的例子:
class Queue {
constructor() {
this.items = [];
}
enqueue(element) {
this.items.push(element);
}
dequeue() {
if (this.isEmpty()) {
return 'Underflow';
}
return this.items.shift();
}
front() {
if (this.isEmpty()) {