Skip to content

Commit fec1c14

Browse files
committed
mvp bfltarrayqueue
1 parent 565d75d commit fec1c14

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

lib/queues.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,31 @@ class BFltArrayQueue {
109109
if (isFull()) {
110110
throw new Error('Enqueue attempted on a full queue.');
111111
} else {
112-
this.rear = (this.rear + 1) % queue.length;
113-
queue[this.rear] = data;
112+
this.rear = (this.rear + 1) % this.queue.length;
113+
this.queue[this.rear] = data;
114114
this.length++;
115115
}
116116
}
117117

118118
dequeue() {
119119
if (isEmpty()) {
120120
throw new Error('Dequeue attempted on empty queue.');
121+
} else {
122+
const toReturn = this.queue[this.front];
123+
this.queue[this.front] = null;
124+
this.front = (this.front + 1) % this.queue.length;
125+
this.length--;
126+
return toReturn;
121127
}
122128
}
123129

124-
peek() {}
130+
peek() {
131+
return this.queue[this.front];
132+
}
125133

126-
length() {}
134+
length() {
135+
return this.length;
136+
}
127137
}
128138

129139
/**

0 commit comments

Comments
 (0)