|
|
@@ -33,31 +33,29 @@ int main(int argc, char** argv) {
|
|
|
|
|
|
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();
|
|
|
+
|
|
|
+ // insert heap top key values into an array backwards to sort from min to max
|
|
|
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();
|
|
|
}
|
|
|
+
|
|
|
+ // convert the new array into a JSON object
|
|
|
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;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ outputJSON["metadata"]["arraySize"] = n;
|
|
|
+ outputJSON["metadata"]["numSamples"] = jsonObject["metadata"]["numSamples"];
|
|
|
std::cout << outputJSON << std::endl;
|
|
|
|
|
|
// clean up memory
|