Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: martinadamsdev/javascript-datastructures-algorithms
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: loiane/javascript-datastructures-algorithms
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
Loading
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -61,16 +61,16 @@ Source code of **Learning JavaScript Data Structures and Algorithms** book, thir
## Installing and running the book examples With Node

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

## Running the examples in the browser

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

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

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

11 changes: 11 additions & 0 deletions examples/chapter10/01-UsingMinHeap.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script src="./../PacktDataStructuresAlgorithms.min.js"></script>
<script src="01-UsingMinHeap.js"></script>
</body>
</html>
27 changes: 27 additions & 0 deletions examples/chapter10/01-UsingMinHeap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const { MinHeap } = PacktDataStructuresAlgorithms;

let heap = new MinHeap();

heap.insert(2);
heap.insert(3);
heap.insert(4);
heap.insert(5);

heap.insert(2);

console.log(heap.getAsArray());

console.log('Heap size: ', heap.size()); // 5
console.log('Heap is empty: ', heap.isEmpty()); // false
console.log('Heap min value: ', heap.findMinimum()); // 1

heap = new MinHeap();
for (let i = 1; i < 10; i++) {
heap.insert(i);
}

console.log(heap.getAsArray());

console.log('Extract minimum: ', heap.extract()); // 1
console.log(heap.getAsArray()); // [2, 4, 3, 8, 5, 6, 7, 9]

11 changes: 11 additions & 0 deletions examples/chapter10/02-UsingMaxHeap.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script src="./../PacktDataStructuresAlgorithms.min.js"></script>
<script src="02-UsingMaxHeap.js"></script>
</body>
</html>
27 changes: 27 additions & 0 deletions examples/chapter10/02-UsingMaxHeap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const { MaxHeap } = PacktDataStructuresAlgorithms;

const maxHeap = new MaxHeap();

maxHeap.insert(2);
maxHeap.insert(3);
maxHeap.insert(4);
maxHeap.insert(5);

maxHeap.insert(1);

console.log(maxHeap.getAsArray());

console.log('Heap size: ', maxHeap.size()); // 5
console.log('Heap is empty: ', maxHeap.isEmpty()); // false
console.log('Heap min value: ', maxHeap.findMinimum()); // 5

maxHeap.insert(6);
maxHeap.insert(9);
maxHeap.insert(10);
maxHeap.insert(14);

console.log(maxHeap.getAsArray());

console.log('Extract minimum: ', maxHeap.extract());
console.log(maxHeap.getAsArray());

11 changes: 11 additions & 0 deletions examples/chapter10/03-HeapSort.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script src="./../PacktDataStructuresAlgorithms.min.js"></script>
<script src="03-HeapSort.js"></script>
</body>
</html>
7 changes: 7 additions & 0 deletions examples/chapter10/03-HeapSort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { heapSort } = PacktDataStructuresAlgorithms;

console.log('********** Heap Sort **********');
const array = [7, 6, 3, 5, 4, 1, 2];

console.log('Before sorting: ', array);
console.log('After sorting: ', heapSort(array));
17 changes: 10 additions & 7 deletions examples/index.html
Original file line number Diff line number Diff line change
@@ -194,15 +194,18 @@
</div>
</section>
<section class="mdl-layout__tab-panel" id="scroll-tab-10">
<div class="page-content">
<div class="page-content mdl-layout--fixed-drawer">
<div class="mdl-layout__drawer is-visible">
<nav class="mdl-navigation">
</nav>
</div>
<div class="page-content">
<div class="page-content mdl-layout--fixed-drawer">
<div class="mdl-layout__drawer is-visible">
<nav class="mdl-navigation">
<a class="mdl-navigation__link" href="chapter10/01-UsingMinHeap.html">01-UsingMinHeap</a>
<a class="mdl-navigation__link" href="chapter10/02-UsingMaxHeap.html">02-UsingMaxHeap</a>
<a class="mdl-navigation__link" href="chapter10/03-HeapSort.html">03-HeapSort</a>
</nav>
</div>
</div>
</section>
</div>
</section>
<section class="mdl-layout__tab-panel" id="scroll-tab-11">
<div class="page-content">
<div class="page-content mdl-layout--fixed-drawer">
Loading