Repository navigation
Expand file tree
/
Copy pathheap.html
More file actions
99 lines (86 loc) · 1.67 KB
/
Copy pathheap.html
File metadata and controls
99 lines (86 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<html>
<head>
<script src="heap.js"></script>
<style>
body {
font-family: arial
}
h1 {
color: blue
}
</style>
</head>
<body>
<h1>Heap</h1>
<script>
var heapArray = [9, 13, 22, 5, 3, 3, 100, 82, 1];
var heap = new Heap(heapArray);
function printHeapAuxiliaryInfo(heap) {
document.write('<i>Size</i>: ' + heap.size());
document.write('<br/>');
document.write('<i>isEmpty</i>: ' + heap.isEmpty());
document.write('<br/>');
document.write('<br/>');
document.write(heap.toString());
}
</script>
<h3>Input List</h3>
<script>
document.write(heapArray.join(', '));
</script>
<h3>Heapify</h3>
<script>
document.write('<i>Array</i>: ' + heap.toStringList());
document.write('<br/>');
printHeapAuxiliaryInfo(heap);
</script>
<h3>Pop</h3>
<script>
document.write('<i>Popped</i>: ' + heap.pop());
document.write('<br/>');
printHeapAuxiliaryInfo(heap);
</script>
<h3>Peek</h3>
<script>
document.write('<i>Peeked</i>: ' + heap.peek());
document.write('<br/>');
printHeapAuxiliaryInfo(heap);
</script>
<h3>Insert (-15)</h3>
<script>
heap.insert(-15);
printHeapAuxiliaryInfo(heap);
</script>
<h3>Insert (202)</h3>
<script>
heap.insert(202);
printHeapAuxiliaryInfo(heap);
</script>
<h3>Pop 3 Times</h3>
<script>
heap.pop();
heap.pop();
heap.pop();
printHeapAuxiliaryInfo(heap);
</script>
<h3>Pop Until 2 Items Left</h3>
<script>
while (heap.size() > 2) {
heap.pop();
}
printHeapAuxiliaryInfo(heap);
</script>
<h3>Pop Until Empty</h3>
<script>
while (!heap.isEmpty()) {
heap.pop();
}
printHeapAuxiliaryInfo(heap);
</script>
<h3>Pop from Empty Heap</h3>
<script>
heap.pop();
printHeapAuxiliaryInfo(heap);
</script>
</body>
</html>