var queue var head var tail -1 function isEmpty return head tail funct

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
var queue = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
var head = 0;
var tail = -1;
function isEmpty() {
return head > tail;
}
function push(x) {
if (tail + 1 > queue.length) {
console.log("Container overflow");
return;
}
queue[tail++] = x;
}
function pop(x) {
if (!isEmpty()) {
return queue[head++];
}
console.log("Empty queue");
}