forked from aaronbloomfield/pdr
-
Notifications
You must be signed in to change notification settings - Fork 228
/
heap-test.cpp
57 lines (53 loc) · 1.65 KB
/
heap-test.cpp
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
// Code written by Aaron Bloomfield, 2014
// Released under a CC BY-SA license
// This code is part of the https://github.com/aaronbloomfield/pdr repository
#include <iostream>
#include <time.h>
#include <stdlib.h>
using namespace std;
#include "binary_heap.h"
binary_heap bh;
int main() {
srand(time(NULL));
cout << "isEmpty(): " << bh.isEmpty() << endl;
try {
cout << bh.findMin() << endl;
} catch (const char *e) {
cout << "Exception thrown: " << e << endl;
}
try {
cout << bh.deleteMin() << endl;
} catch (const char *e) {
cout << "Exception thrown: " << e << endl;
}
cout << "inserting a value into the heap..." << endl;
bh.insert(rand() % 1000);
cout << "isEmpty(): " << bh.isEmpty() << endl;
try {
cout << bh.findMin() << endl;
} catch (const char *e) {
cout << "Exception thrown: " << e << endl;
}
for ( int i = 0; i < 40; i++ )
bh.insert(rand() % 1000);
cout << bh.findMin() << endl;
cout << "size: " << bh.size() << endl;
bh.print();
cout << "deleting min..." << endl;
int min = bh.deleteMin();
cout << "\t" << min << endl;
cout << "size: " << bh.size() << endl;
bh.print();
cout << "isEmpty(): " << bh.isEmpty() << endl;
cout << "calling makeEmpty()" << endl;
bh.makeEmpty();
cout << "isEmpty(): " << bh.isEmpty() << endl;
cout << "inserting a value into the heap..." << endl;
bh.insert(100);
cout << "size: " << bh.size() << endl;
cout << "deleting min..." << endl;
bh.deleteMin();
cout << "size: " << bh.size() << endl;
cout << "isEmpty(): " << bh.isEmpty() << endl;
return 0;
}