-
Notifications
You must be signed in to change notification settings - Fork 52
/
queue.html
43 lines (39 loc) · 888 Bytes
/
queue.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<html>
<head>
<title>Queue in JavaScript</title>
<script>
let queue = [];
let currentSize = queue.length;
let maxSize = 5;
function enqueue(newVal) {
if (currentSize >= maxSize) {
alert("Queue is already full");
} else {
queue[currentSize] = newVal;
currentSize++;
}
}
function display() {
console.warn(queue);
}
function dequeue() {
if (currentSize > 0) {
for (let i = 0; i < queue.length; i++) {
queue[i] = queue[i + 1];
}
currentSize--;
queue.length = currentSize;
} else {
alert("queue is already empty");
}
}
enqueue(10);
enqueue(20);
enqueue(30);
display();
</script>
</head>
<body>
<h1>Queue in JavaScript</h1>
</body>
</html>