Skip to content

Commit 7f99c56

Browse files
authored
Merge pull request #1 from loiane/master
Master
2 parents 2db3d12 + ec96129 commit 7f99c56

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+6618
-6414
lines changed

.eslintrc.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
"prefer-destructuring": ["error", {"object": true, "array": false}],
3333
"padded-blocks": 0,
3434
"no-sparse-arrays": 0,
35-
"array-bracket-spacing": 0
35+
"array-bracket-spacing": 0,
36+
"import/no-named-as-default": 0,
37+
"implicit-arrow-linebreak": 0
3638
}
3739
}

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Learning JavaScript Data Structures and Algorithms
22
====================================
33

4-
[![Build Status](https://travis-ci.org/loiane/javascript-datastructures-algorithms.svg?branch=third-edition)](https://travis-ci.org/loiane/javascript-datastructures-algorithms)
4+
[![Build Status](https://travis-ci.org/loiane/javascript-datastructures-algorithms.svg?branch=master)](https://travis-ci.org/loiane/javascript-datastructures-algorithms)
55
[![codecov](https://codecov.io/gh/loiane/javascript-datastructures-algorithms/branch/master/graph/badge.svg)](https://codecov.io/gh/loiane/javascript-datastructures-algorithms)
66
[![devDependencies Status](https://david-dm.org/loiane/javascript-datastructures-algorithms/dev-status.svg)](https://david-dm.org/loiane/javascript-datastructures-algorithms?type=dev)
77
[![dependencies Status](https://david-dm.org/loiane/javascript-datastructures-algorithms/status.svg)](https://david-dm.org/loiane/javascript-datastructures-algorithms)
@@ -61,16 +61,16 @@ Source code of **Learning JavaScript Data Structures and Algorithms** book, thir
6161
## Installing and running the book examples With Node
6262

6363
* Install [Node](https://nodejs.org)
64-
* Open terminal/cmd and change directoty to this project folder: `cd /Users/.../javascript-datastructures-algorithms` (Linux/Max) or `cd C:/.../javascript-datastructures-algorithms`
65-
* run `npm install` to install all depencies
64+
* Open terminal/cmd and change directory to this project folder: `cd /Users/.../javascript-datastructures-algorithms` (Linux/Max) or `cd C:/.../javascript-datastructures-algorithms`
65+
* run `npm install` to install all dependencies
6666
* To see the examples, run `http-server html` or `npm run serve`. Open your browser `http:\\localhost:8080` to see the book examples
6767
* Or `cd html/chapter01` and run each javascript file with node: `node 02-Variables`
6868

6969
## Running the examples in the browser
7070

7171
* Right click on the html file you would like to see the examples, right click and 'Open with Chrome (or any other browser)'
7272

73-
* Or open the `examples/index.html` file to easily nagivate through all examples:
73+
* Or open the `examples/index.html` file to easily navigate through all examples:
7474

7575
* Demo: [https://javascript-ds-algorithms-book.firebaseapp.com](https://javascript-ds-algorithms-book.firebaseapp.com)
7676

@@ -100,6 +100,8 @@ Book link - second edition:
100100
Book link - third edition:
101101
- [Packt](https://www.packtpub.com/web-development/learning-javascript-data-structures-and-algorithms-third-edition)
102102
- [Amazon](http://a.co/cbMlYmJ)
103+
- [Chinese version](http://www.ituring.com.cn/book/2653)
104+
- [Brazilian Portuguese version](https://novatec.com.br/livros/estruturas-de-dados-algoritmos-em-javascript-2ed/)
103105

104106
### Found an issue or have a question?
105107

+11
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-UsingMinHeap.js"></script>
10+
</body>
11+
</html>

examples/chapter10/01-UsingMinHeap.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const { MinHeap } = PacktDataStructuresAlgorithms;
2+
3+
let heap = new MinHeap();
4+
5+
heap.insert(2);
6+
heap.insert(3);
7+
heap.insert(4);
8+
heap.insert(5);
9+
10+
heap.insert(2);
11+
12+
console.log(heap.getAsArray());
13+
14+
console.log('Heap size: ', heap.size()); // 5
15+
console.log('Heap is empty: ', heap.isEmpty()); // false
16+
console.log('Heap min value: ', heap.findMinimum()); // 1
17+
18+
heap = new MinHeap();
19+
for (let i = 1; i < 10; i++) {
20+
heap.insert(i);
21+
}
22+
23+
console.log(heap.getAsArray());
24+
25+
console.log('Extract minimum: ', heap.extract()); // 1
26+
console.log(heap.getAsArray()); // [2, 4, 3, 8, 5, 6, 7, 9]
27+
+11
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-UsingMaxHeap.js"></script>
10+
</body>
11+
</html>

examples/chapter10/02-UsingMaxHeap.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const { MaxHeap } = PacktDataStructuresAlgorithms;
2+
3+
const maxHeap = new MaxHeap();
4+
5+
maxHeap.insert(2);
6+
maxHeap.insert(3);
7+
maxHeap.insert(4);
8+
maxHeap.insert(5);
9+
10+
maxHeap.insert(1);
11+
12+
console.log(maxHeap.getAsArray());
13+
14+
console.log('Heap size: ', maxHeap.size()); // 5
15+
console.log('Heap is empty: ', maxHeap.isEmpty()); // false
16+
console.log('Heap min value: ', maxHeap.findMinimum()); // 5
17+
18+
maxHeap.insert(6);
19+
maxHeap.insert(9);
20+
maxHeap.insert(10);
21+
maxHeap.insert(14);
22+
23+
console.log(maxHeap.getAsArray());
24+
25+
console.log('Extract minimum: ', maxHeap.extract());
26+
console.log(maxHeap.getAsArray());
27+

examples/chapter10/03-HeapSort.html

+11
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-HeapSort.js"></script>
10+
</body>
11+
</html>

examples/chapter10/03-HeapSort.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const { heapSort } = PacktDataStructuresAlgorithms;
2+
3+
console.log('********** Heap Sort **********');
4+
const array = [7, 6, 3, 5, 4, 1, 2];
5+
6+
console.log('Before sorting: ', array);
7+
console.log('After sorting: ', heapSort(array));

examples/index.html

+10-7
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,18 @@
194194
</div>
195195
</section>
196196
<section class="mdl-layout__tab-panel" id="scroll-tab-10">
197-
<div class="page-content">
198-
<div class="page-content mdl-layout--fixed-drawer">
199-
<div class="mdl-layout__drawer is-visible">
200-
<nav class="mdl-navigation">
201-
</nav>
202-
</div>
197+
<div class="page-content">
198+
<div class="page-content mdl-layout--fixed-drawer">
199+
<div class="mdl-layout__drawer is-visible">
200+
<nav class="mdl-navigation">
201+
<a class="mdl-navigation__link" href="chapter10/01-UsingMinHeap.html">01-UsingMinHeap</a>
202+
<a class="mdl-navigation__link" href="chapter10/02-UsingMaxHeap.html">02-UsingMaxHeap</a>
203+
<a class="mdl-navigation__link" href="chapter10/03-HeapSort.html">03-HeapSort</a>
204+
</nav>
203205
</div>
204206
</div>
205-
</section>
207+
</div>
208+
</section>
206209
<section class="mdl-layout__tab-panel" id="scroll-tab-11">
207210
<div class="page-content">
208211
<div class="page-content mdl-layout--fixed-drawer">

0 commit comments

Comments
 (0)