Skip to content

Commit cee5c1e

Browse files
authored
Merge pull request loiane#46 from loiane/third-edition
[Heap]
2 parents bb112a0 + 5ee6666 commit cee5c1e

File tree

17 files changed

+168
-21
lines changed

17 files changed

+168
-21
lines changed

examples/PacktDataStructuresAlgorithms.min.js

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

examples/PacktDataStructuresAlgorithms.min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
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-UsingMinHeap.js"></script>
10+
</body>
11+
</html>

examples/chapter10/01-UsingMinHeap.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const { MinHeap } = PacktDataStructuresAlgorithms;
2+
3+
const heap = new MinHeap();
4+
5+
heap.insert(2);
6+
heap.insert(3);
7+
heap.insert(4);
8+
heap.insert(5);
9+
10+
heap.insert(1);
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.insert(6);
19+
heap.insert(7);
20+
21+
console.log(heap.getAsArray());
22+
23+
console.log('Extract minimum: ', heap.extract());
24+
console.log(heap.getAsArray());
25+
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-UsingMaxHeap.js"></script>
10+
</body>
11+
</html>

examples/chapter10/02-UsingMaxHeap.js

Lines changed: 27 additions & 0 deletions
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

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

examples/chapter10/03-HeapSort.js

Lines changed: 7 additions & 0 deletions
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/chapter11/03-DFS.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ graph.addEdge('C', 'F');
4646
graph.addEdge('F', 'E');
4747

4848
const result = DFS(graph);
49-
console.log(result.discovery);
50-
console.log(result.finished);
51-
console.log(result.predecessors);
49+
console.log('discovery', result.discovery);
50+
console.log('finished', result.finished);
51+
console.log('predecessors', result.predecessors);
5252

5353
const fTimes = result.finished;
5454
s = '';

examples/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,19 @@
190190
</div>
191191
</div>
192192
</section>
193+
<section class="mdl-layout__tab-panel" id="scroll-tab-10">
194+
<div class="page-content">
195+
<div class="page-content mdl-layout--fixed-drawer">
196+
<div class="mdl-layout__drawer is-visible">
197+
<nav class="mdl-navigation">
198+
<a class="mdl-navigation__link" href="chapter10/01-UsingMinHeap.html">01-UsingMinHeap</a>
199+
<a class="mdl-navigation__link" href="chapter10/02-UsingMaxHeap.html">02-UsingMaxHeap</a>
200+
<a class="mdl-navigation__link" href="chapter10/03-HeapSort.html">03-HeapSort</a>
201+
</nav>
202+
</div>
203+
</div>
204+
</div>
205+
</section>
193206
<section class="mdl-layout__tab-panel" id="scroll-tab-11">
194207
<div class="page-content">
195208
<div class="page-content mdl-layout--fixed-drawer">

0 commit comments

Comments
 (0)