Skip to content

Commit 5eabb7b

Browse files
committed
chapter 04: [Queues and Deques]
1 parent ea30d2c commit 5eabb7b

32 files changed

+1468
-45
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Work in Progress.
1313
* 01: [JavaScript, ECMAScript and TypeScript: a quick overview](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter01)
1414
* 02: [Arrays](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter02)
1515
* 03: [Stacks](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter03)
16+
* 04: [Queues and Deques](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter04)
1617

1718
## Thrid Edition Updates
1819

examples/PacktDataStructuresAlgorithms.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/chapter04/01-Queue.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title></title>
6+
</head>
7+
<body>
8+
<script src="./../PacktDataStructuresAlgorithms.min.js"></script>
9+
<script src="01-Queue.js"></script>
10+
</body>
11+
</html>

examples/chapter04/01-Queue.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const { Queue } = PacktDataStructuresAlgorithms;
2+
3+
const queue = new Queue();
4+
console.log(queue.isEmpty()); // outputs true
5+
queue.enqueue('John');
6+
queue.enqueue('Jack');
7+
console.log(queue.toString()); // John,Jack
8+
queue.enqueue('Camila');
9+
console.log(queue.toString()); // John,Jack,Camila
10+
console.log(queue.size()); // outputs 3
11+
console.log(queue.isEmpty()); // outputs false
12+
queue.dequeue();
13+
queue.dequeue();
14+
console.log(queue.toString()); // Camila

examples/chapter04/02-Deque.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title></title>
6+
</head>
7+
<body>
8+
<script src="./../PacktDataStructuresAlgorithms.min.js"></script>
9+
<script src="02-Deque.js"></script>
10+
</body>
11+
</html>

examples/chapter04/02-Deque.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const { Deque } = PacktDataStructuresAlgorithms;
2+
3+
const deque = new Deque();
4+
console.log(deque.isEmpty()); // outputs true
5+
deque.addBack('John');
6+
deque.addBack('Jack');
7+
console.log(deque.toString()); // John,Jack
8+
deque.addBack('Camila');
9+
console.log(deque.toString()); // John,Jack,Camila
10+
console.log(deque.size()); // outputs 3
11+
console.log(deque.isEmpty()); // outputs false
12+
deque.removeFront();
13+
console.log(deque.toString()); // Jack,Camila
14+
deque.removeBack(); // Camila decides to leave
15+
console.log(deque.toString()); // Jack
16+
deque.addFront('John');
17+
console.log(deque.toString()); // John,Jack

examples/chapter04/03-HotPotato.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title></title>
6+
</head>
7+
<body>
8+
<script src="./../PacktDataStructuresAlgorithms.min.js"></script>
9+
<script src="03-HotPotato.js"></script>
10+
</body>
11+
</html>

examples/chapter04/03-HotPotato.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { hotPotato } = PacktDataStructuresAlgorithms;
2+
3+
const names = ['John', 'Jack', 'Camila', 'Ingrid', 'Carl'];
4+
const result = hotPotato(names, 7);
5+
6+
result.eliminated.forEach(name => {
7+
console.log(`${name} was eliminated from the Hot Potato game.`);
8+
});
9+
10+
console.log(`The winner is: ${result.winner}`);
11+
12+
// Camila was eliminated from the Hot Potato game.
13+
// Jack was eliminated from the Hot Potato game.
14+
// Carl was eliminated from the Hot Potato game.
15+
// Ingrid was eliminated from the Hot Potato game.
16+
// The winner is: John
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title></title>
6+
</head>
7+
<body>
8+
<script src="./../PacktDataStructuresAlgorithms.min.js"></script>
9+
<script src="04-PalindromeChecker.js"></script>
10+
</body>
11+
</html>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const { palindromeChecker } = PacktDataStructuresAlgorithms;
2+
3+
console.log('a', palindromeChecker('a'));
4+
console.log('aa', palindromeChecker('aa'));
5+
console.log('kayak', palindromeChecker('kayak'));
6+
console.log('level', palindromeChecker('level'));
7+
console.log('Was it a car or a cat I saw', palindromeChecker('Was it a car or a cat I saw'));
8+
console.log('Step on no pets', palindromeChecker('Step on no pets'));

0 commit comments

Comments
 (0)