|
|
@@ -19,19 +19,49 @@ int main(int argc, char** argv) {
|
|
|
|
|
|
std::string sampleName; // Sample key name to iterate
|
|
|
nlohmann::json outputJSON; // output JSON file
|
|
|
- //int currValue = 0; // current key value
|
|
|
+ int currValue = 0; // current key value
|
|
|
|
|
|
int n = jsonObject["metadata"]["arraySize"];
|
|
|
|
|
|
+ std::vector<int> A(n, 0);
|
|
|
+
|
|
|
class PriorityQueue sampleHeap;
|
|
|
sampleHeap.initiateHeap(n);
|
|
|
|
|
|
for (auto itr = jsonObject.begin(); itr != jsonObject.end(); ++itr) {
|
|
|
+ sampleName = itr.key();
|
|
|
+
|
|
|
if (sampleName != "metadata") {
|
|
|
+ nlohmann::json topOfHeap;
|
|
|
for (auto arrayItr = jsonObject[sampleName].begin(); arrayItr != jsonObject[sampleName].end(); ++arrayItr) {
|
|
|
+ // insert each array element into heap
|
|
|
+ currValue = *arrayItr;
|
|
|
+ sampleHeap.insert(currValue);
|
|
|
+ }
|
|
|
+ std::cout << "before sorting" << std::endl;
|
|
|
+ sampleHeap.printArray();
|
|
|
+ for (int i = n - 1; i >= 0; i--) {
|
|
|
+ // insert heap.top into array A backwards to sort the array from min to max
|
|
|
+ A[i] = sampleHeap.returnMax();
|
|
|
+ // remove the max value from the heap
|
|
|
+ sampleHeap.removeMax();
|
|
|
+ std::cout << "after sorting" << std::endl;
|
|
|
+ sampleHeap.printArray();
|
|
|
}
|
|
|
+ for (int j = 0; j <= n - 1; j++) {
|
|
|
+ // adding values directly to JSON object
|
|
|
+ topOfHeap.push_back(A[j]);
|
|
|
+ std::cout << A[j] << ", ";
|
|
|
+ }
|
|
|
+ std::cout << std::endl;
|
|
|
+ outputJSON[sampleName] = topOfHeap;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
std::cout << outputJSON << std::endl;
|
|
|
+
|
|
|
+ // clean up memory
|
|
|
file.close();
|
|
|
+ sampleHeap.deleteHeap();
|
|
|
+ return 0;
|
|
|
}
|