-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
208 lines (146 loc) · 6.27 KB
/
main.cpp
File metadata and controls
208 lines (146 loc) · 6.27 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// Ana Taylor
// p4.cpp
// Driver
#include <iostream>
#include "heap.h"
#include "heap.cpp"
using namespace std;
const int INITIAL_SIZE = 5;
int main() {
cout << endl << endl << endl;
cout << "------------- START OF TEST ----------------" << endl;
cout << "--------------------------------------------" << endl;
cout << "Creating a resizable heap (heap1) of initial size " << INITIAL_SIZE << "..." << endl;
Heap heap1(INITIAL_SIZE);
cout << "Heap of size " << INITIAL_SIZE << " created." << endl;
cout << endl << endl;
cin.get();
cout << "------- TESTING THE insert AND resize FUNCTIONS _______" << endl;
cout << "-------------------------------------------------------" << endl;
cout << "Inserting values in heap1..." << endl;
cout << "The heap will accept duplicate values and will be re-sized " << endl;
cout << "if attempting to insert more values that its initial size. " << endl << endl;
cout << "Inserting 13 ..." << endl;
heap1.insert(13);
cout << "Inserting 14 ..." << endl;
heap1.insert(14);
cout << "Inserting 16 ..." << endl;
heap1.insert(16);
cout << "Inserting 24 ..." << endl;
heap1.insert(24);
cout << "Inserting 21 ..." << endl;
heap1.insert(21);
cout << "Inserting 19 ..." << endl;
heap1.insert(19);
cout << "Inserting 68 ..." << endl;
heap1.insert(68);
cout << "Inserting 65 ..." << endl;
heap1.insert(65);
cout << "Inserting 26 ..." << endl;
heap1.insert(26);
cout << "Inserting 32 ..." << endl;
heap1.insert(32);
cout << "Inserting 65 ..." << endl;
heap1.insert(65);
cout << "Inserting 26 ..." << endl;
heap1.insert(26);
cout << "Inserting 32 ..." << endl;
heap1.insert(32);
cout << endl;
cin.get();
cout << "-------- TESTING THE COPY CONSTRUCTOR--------" << endl;
cout << "---------------------------------------------" << endl;
cout << "Creating heap2 that is the copy of heap1..." << endl;
Heap heap2(heap1);
cout << "heap2 created. " << endl;
cout << endl << endl;
cin.get();
cout << "---- TESTING THE remove AND bubbleDown FUNCTION on heap2 ----" << endl;
cout << "-------------------------------------------------------------" << endl;
cout << "Removing values from heap2 and printing the priorities ..." << endl;
cout << "The priorities should be the same at this point ..." << endl << endl;
for (int i = 1; i <= heap2.getHeapCapacity(); i++) {
cout << "Previous priority is: " << heap2.getPreviousPriority(i) << endl;
cout << "Updated priority is: " << heap2.getCurrentPriority(i) << endl << endl;
}
cin.get();
cout << "Now removing values from heap2..." << endl;
while(!heap2.isEmpty()) {
cout << heap2.remove() << endl;
}
cout << endl;
cout << "Values removed form heap2. " << endl;
cout << "Now trying to remove 3 more values..." << endl;
heap2.remove();
heap2.remove();
heap2.remove();
cout << "Unable to remove because the heap2 is empty." << endl;
cout << endl << endl;
cin.get();
cout << "-------- TESTING THE OVERLOADED ASSIGNMENT OPERATOR --------" << endl;
cout << "------------------------------------------------------------" << endl;
cout << "Creating heap3 that is the copy of heap1..." << endl;
Heap heap3 = heap1;
cout << "heap3 created. " << endl;
cout << endl << endl;
cin.get();
cout << "---- TESTING THE remove AND bubbleDown FUNCTION on heap3 ----" << endl;
cout << "-------------------------------------------------------------" << endl;
cout << "Printing the priorities of heap3 then removing values: " << endl;
for (int i = 1; i <= heap3.getHeapCapacity(); i++) {
cout << "Previous priority is: " << heap3.getPreviousPriority(i) << endl;
cout << "Updated priority is: " << heap3.getCurrentPriority(i) << endl << endl;
}
cin.get();
cout << "Now removing values from heap3..." << endl;
while(!heap3.isEmpty()) {
cout << heap3.remove() << endl;
}
cout << endl;
cout << "Values removed form heap3. " << endl;
cout << "Now trying to remove 3 more values..." << endl;
heap3.remove();
heap3.remove();
heap3.remove();
cout << "Unable to remove because the heap3 is empty." << endl;
cout << endl << endl;
cin.get();
cout << "----- TESTING THE resetPriority FUNCTION -----" << endl;
cout << "---------------------------------------------------------" << endl;
cout << "The priority will be changed to the (minimum priority in the heap - 1) " << endl;
cout << "to ensure the new priority is the highest priority and to bubble up. " << endl;
cout << "Choosing the values from heap1 for a priority reset..." << endl;
cout << endl << endl;
cin.get();
cout << "Resetting priority of 21..." << endl;
heap1.resetPriority(21);
cout << "Now printing the previous and updated priority... " << endl;
cout << "Previous priority is: " << heap1.getPreviousPriority(1) << endl;
cout << "Updated priority is: " << heap1.getCurrentPriority(1) << endl << endl;
cout << "----------------------------------------------------------" << endl;
cout << endl;
cin.get();
cout << "Resetting priority of 32..." << endl;
heap1.resetPriority(32);
cout << "Now printing the previous and updated priority... " << endl;
cout << "Previous priority is: " << heap1.getPreviousPriority(1) << endl;
cout << "Updated priority is: " << heap1.getCurrentPriority(1) << endl << endl;
cout << "----------------------------------------------------------" << endl;
cout << endl;
cin.get();
cout << "Resetting priority of 14..." << endl;
heap1.resetPriority(14);
cout << "Now printing the previous and updated priority... " << endl;
cout << "Previous priority is: " << heap1.getPreviousPriority(1) << endl;
cout << "Updated priority is: " << heap1.getCurrentPriority(1) << endl << endl;
cout << "----------------------------------------------------------" << endl;
cout << endl;
cin.get();
cout << "Now removing the values in heap1..." << endl;
while(!heap1.isEmpty()) {
cout << heap1.remove() << endl;
}
cout << endl << endl;
cout << "-------- END OF TEST --------" << endl;
return 0;
}