Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5714935

Browse files
Merge pull request #11 from num-dev/numdev-queue
Queue DS with Functions
2 parents f50f43d + c57f9bd commit 5714935

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

‎Queue/1.Queue-with-function.html‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<title>Queue</title>
9+
</head>
10+
11+
<body>
12+
<div align="center">
13+
<h3>Queue with Function</h3>
14+
<p>(Open console to check output)</p>
15+
</div>
16+
17+
<script>
18+
let queue = [];
19+
let currentIndex = queue.length;
20+
let maxSize = 4;
21+
22+
function enQueue(newVal) {
23+
if (currentIndex >= maxSize) {
24+
console.error("Queue is already full");
25+
return false;
26+
}
27+
queue[currentIndex] = newVal;
28+
currentIndex++;
29+
}
30+
31+
function deQueue() {
32+
if (currentIndex > 0) {
33+
for (let i = 0; i < queue.length; i++) {
34+
queue[i] = queue[i + 1];
35+
}
36+
currentIndex--;
37+
queue.length--;
38+
} else {
39+
console.error("Queue is Empty.");
40+
}
41+
}
42+
43+
function display() {
44+
console.log(queue);
45+
}
46+
47+
enQueue(5);
48+
enQueue(10);
49+
enQueue(8);
50+
display();
51+
52+
</script>
53+
</body>
54+
55+
</html>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /