<!DOCTYPE html>
<html>
<head>
<title>Dequeue Operation
in
Queue</title>
<meta charset=
"UTF-8"
>
<script src=
type=
"text/javascript"
></script>
<style>
body {
padding: 0;
margin: 0;
}
canvas {
vertical-align: top;
}
</style>
</head>
<body>
<script>
function
Queue(array) {
this
.array = [];
if
(array)
this
.array = array;
}
Queue.prototype.getBuffer =
function
() {
return
this
.array.slice();
}
Queue.prototype.isEmpty =
function
() {
return
this
.array.length == 0;
}
var
queue1 =
new
Queue();
console.log(queue1);
Queue.prototype.enqueue =
function
(value) {
this
.array.push(value);
}
function
setup() {
createCanvas(displayWidth, 300);
}
function
draw() {
background(
"grey"
);
strokeWeight(3);
textAlign(CENTER);
textSize(24);
text(
"Queue Implementation Using P5.js"
,
windowWidth/2, 20);
textAlign(LEFT);
textSize(14);
stroke(
'green'
);
line(10, 45, 90, 45);
rect(10, 30, 60, 30);
noStroke();
text(
"FRONT"
, 20, 50);
for
(
var
i = 0; i <= queue1[
'array'
].length-1; i++) {
var
p = 10;
translate(70, 0);
strokeWeight(3);
stroke(
'green'
);
line(10+p, 45, p+80, 45);
rect(10+p, 30, 40+p, 30);
noStroke();
text(queue1[
'array'
][i], 40, 50);
p += 10;
}
stroke(
'green'
);
translate(70, 0);
rect(10, 30, 60, 30);
noStroke();
text(
"REAR"
, 20, 50);
}
Queue.prototype.dequeue =
function
() {
return
this
.array.shift();
}
Queue.prototype.peek =
function
() {
return
this
.array[
this
.array.length-1];
}
queue1.enqueue(1);
queue1.enqueue(2);
queue1.enqueue(3);
queue1.enqueue(19);
queue1.enqueue(11);
queue1.enqueue(15);
queue1.enqueue(14);
queue1.enqueue(18);
queue1.enqueue(25);
queue1.dequeue();
queue1.dequeue();
</script>
</body>
</html>