-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.html
47 lines (45 loc) · 1.08 KB
/
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
44
45
46
47
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
let queue = [];
let currentSize = queue.length;
let maxsize = 5;
function enqueue(newval){
if (currentSize<maxsize) {
queue[currentSize]=newval;
currentSize++;
}else{
console.log('queue is already is full');
}
}
function dqueue() {
if (currentSize>0) {
for (let i = 0; i < maxsize; i++) {
queue[i]=queue[i+1];
}
currentSize--
queue.length =currentSize
}
else{
console.log('queue is already empty');
}
}
function display(){
console.log(queue)
}
enqueue(30)
enqueue(31)
enqueue(32)
enqueue(33)
enqueue(34)
dqueue()
display()
</script>
</body>
</html>