forked from aaronbloomfield/pdr
-
Notifications
You must be signed in to change notification settings - Fork 228
/
heap-test.cpp.html
71 lines (67 loc) · 11.2 KB
/
heap-test.cpp.html
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
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite">
<title>heap-test.cpp</title>
</head>
<body style="background-color:white">
<pre><i><span style="color:#9A1900">// Code written by Aaron Bloomfield, 2014</span></i>
<i><span style="color:#9A1900">// Released under a CC BY-SA license</span></i>
<i><span style="color:#9A1900">// This code is part of the https://github.com/aaronbloomfield/pdr repository</span></i>
<b><span style="color:#000080">#include</span></b> <span style="color:#FF0000"><iostream></span>
<b><span style="color:#000080">#include</span></b> <span style="color:#FF0000"><time.h></span>
<b><span style="color:#000080">#include</span></b> <span style="color:#FF0000"><stdlib.h></span>
<b><span style="color:#0000FF">using</span></b> <b><span style="color:#0000FF">namespace</span></b> std<span style="color:#990000">;</span>
<b><span style="color:#000080">#include</span></b> <span style="color:#FF0000">"binary_heap.h"</span>
<span style="color:#008080">binary_heap</span> bh<span style="color:#990000">;</span>
<span style="color:#009900">int</span> <b><span style="color:#000000">main</span></b><span style="color:#990000">()</span> <span style="color:#FF0000">{</span>
<b><span style="color:#000000">srand</span></b><span style="color:#990000">(</span><b><span style="color:#000000">time</span></b><span style="color:#990000">(</span>NULL<span style="color:#990000">));</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"isEmpty(): "</span> <span style="color:#990000"><<</span> bh<span style="color:#990000">.</span><b><span style="color:#000000">isEmpty</span></b><span style="color:#990000">()</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">try</span></b> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> bh<span style="color:#990000">.</span><b><span style="color:#000000">findMin</span></b><span style="color:#990000">()</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span> <b><span style="color:#0000FF">catch</span></b> <span style="color:#990000">(</span><b><span style="color:#0000FF">const</span></b> <span style="color:#009900">char</span> <span style="color:#990000">*</span>e<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"Exception thrown: "</span> <span style="color:#990000"><<</span> e <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
<b><span style="color:#0000FF">try</span></b> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> bh<span style="color:#990000">.</span><b><span style="color:#000000">deleteMin</span></b><span style="color:#990000">()</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span> <b><span style="color:#0000FF">catch</span></b> <span style="color:#990000">(</span><b><span style="color:#0000FF">const</span></b> <span style="color:#009900">char</span> <span style="color:#990000">*</span>e<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"Exception thrown: "</span> <span style="color:#990000"><<</span> e <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"inserting a value into the heap..."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
bh<span style="color:#990000">.</span><b><span style="color:#000000">insert</span></b><span style="color:#990000">(</span><b><span style="color:#000000">rand</span></b><span style="color:#990000">()</span> <span style="color:#990000">%</span> <span style="color:#993399">1000</span><span style="color:#990000">);</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"isEmpty(): "</span> <span style="color:#990000"><<</span> bh<span style="color:#990000">.</span><b><span style="color:#000000">isEmpty</span></b><span style="color:#990000">()</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">try</span></b> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> bh<span style="color:#990000">.</span><b><span style="color:#000000">findMin</span></b><span style="color:#990000">()</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span> <b><span style="color:#0000FF">catch</span></b> <span style="color:#990000">(</span><b><span style="color:#0000FF">const</span></b> <span style="color:#009900">char</span> <span style="color:#990000">*</span>e<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"Exception thrown: "</span> <span style="color:#990000"><<</span> e <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
<b><span style="color:#0000FF">for</span></b> <span style="color:#990000">(</span> <span style="color:#009900">int</span> i <span style="color:#990000">=</span> <span style="color:#993399">0</span><span style="color:#990000">;</span> i <span style="color:#990000"><</span> <span style="color:#993399">40</span><span style="color:#990000">;</span> i<span style="color:#990000">++</span> <span style="color:#990000">)</span>
bh<span style="color:#990000">.</span><b><span style="color:#000000">insert</span></b><span style="color:#990000">(</span><b><span style="color:#000000">rand</span></b><span style="color:#990000">()</span> <span style="color:#990000">%</span> <span style="color:#993399">1000</span><span style="color:#990000">);</span>
cout <span style="color:#990000"><<</span> bh<span style="color:#990000">.</span><b><span style="color:#000000">findMin</span></b><span style="color:#990000">()</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"size: "</span> <span style="color:#990000"><<</span> bh<span style="color:#990000">.</span><b><span style="color:#000000">size</span></b><span style="color:#990000">()</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
bh<span style="color:#990000">.</span><b><span style="color:#000000">print</span></b><span style="color:#990000">();</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"deleting min..."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<span style="color:#009900">int</span> min <span style="color:#990000">=</span> bh<span style="color:#990000">.</span><b><span style="color:#000000">deleteMin</span></b><span style="color:#990000">();</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"</span><span style="color:#CC33CC">\t</span><span style="color:#FF0000">"</span> <span style="color:#990000"><<</span> min <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"size: "</span> <span style="color:#990000"><<</span> bh<span style="color:#990000">.</span><b><span style="color:#000000">size</span></b><span style="color:#990000">()</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
bh<span style="color:#990000">.</span><b><span style="color:#000000">print</span></b><span style="color:#990000">();</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"isEmpty(): "</span> <span style="color:#990000"><<</span> bh<span style="color:#990000">.</span><b><span style="color:#000000">isEmpty</span></b><span style="color:#990000">()</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"calling makeEmpty()"</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
bh<span style="color:#990000">.</span><b><span style="color:#000000">makeEmpty</span></b><span style="color:#990000">();</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"isEmpty(): "</span> <span style="color:#990000"><<</span> bh<span style="color:#990000">.</span><b><span style="color:#000000">isEmpty</span></b><span style="color:#990000">()</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"inserting a value into the heap..."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
bh<span style="color:#990000">.</span><b><span style="color:#000000">insert</span></b><span style="color:#990000">(</span><span style="color:#993399">100</span><span style="color:#990000">);</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"size: "</span> <span style="color:#990000"><<</span> bh<span style="color:#990000">.</span><b><span style="color:#000000">size</span></b><span style="color:#990000">()</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"deleting min..."</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
bh<span style="color:#990000">.</span><b><span style="color:#000000">deleteMin</span></b><span style="color:#990000">();</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"size: "</span> <span style="color:#990000"><<</span> bh<span style="color:#990000">.</span><b><span style="color:#000000">size</span></b><span style="color:#990000">()</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"isEmpty(): "</span> <span style="color:#990000"><<</span> bh<span style="color:#990000">.</span><b><span style="color:#000000">isEmpty</span></b><span style="color:#990000">()</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">return</span></b> <span style="color:#993399">0</span><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
</pre>
</body>
</html>