-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaxHeapQuestion.cpp
More file actions
41 lines (38 loc) · 1.3 KB
/
MaxHeapQuestion.cpp
File metadata and controls
41 lines (38 loc) · 1.3 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
// student no: A00030840
#include "MaxHeapQuestion.h";
#include "MaxHeap.h";
#include <string>
void MaxHeapQuestion::start_max_heap(string InputFileName, string OutputFileName) {
int numberElements = extractValues.number_elements(InputFileName);
int *dataElements = new int[numberElements];
int iterations = 0;
int pointer = 0;
MaxHeap maxHeap;
dataElements = extractValues.get_elements(InputFileName, numberElements);
for (int i = 0; i < numberElements; i++) {
maxHeap.insert(dataElements[i]);
if (i >= 1) {
for (int c = 0; c <= i; c++) {
// data elements before insertion.
utility.writeToLastLine(OutputFileName, std::to_string(dataElements[iterations]) + " ");
iterations++;
}
iterations = 0;
utility.writeToLastLine(OutputFileName, "\n");
for (int x = 0; x <= i; x++) {
// elements inserted.
utility.writeToLastLine(OutputFileName, std::to_string(maxHeap.heap[pointer]) + " ");
pointer++;
}
pointer = 0;
utility.writeToLastLine(OutputFileName, "\n");
}
else {
utility.writeToLastLine(OutputFileName, std::to_string(dataElements[i]) + " ");
utility.writeToLastLine(OutputFileName, "\n");
utility.writeToLastLine(OutputFileName, std::to_string(maxHeap.heap[i]) + " ");
utility.writeToLastLine(OutputFileName, "\n");
}
}
delete[] dataElements;
}