Skip to content

Commit ec96129

Browse files
author
Loiane Groner
committed
restored chapter 10 examples
1 parent 8151ba0 commit ec96129

7 files changed

+104
-7
lines changed
+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)