Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program that does the following: 1. reads a JSON file of heap operations, 2. executes the heap operations from the JSON file, 3.
Write a program that does the following:
1. reads a JSON file of heap operations,
2. executes the heap operations from the JSON file,
3. prints the priority queue as a JSON object to stdout.
The contents of BuildExample.json, an example of a JSON file of operations, is as
follows:
{
"Op01": {
"key": 3804,
"operation": "insert"
},
"Op02": {
"key": 4035,
"operation": "insert"
},
"Op03": {
"key": 1755,
"operation": "insert"
},
"Op04": {
"operation": "removeMax"
},
"Op05": {
"key": 2109,
"operation": "insert"
},
"Op06": {
"key": 3333,
"operation": "insert"
},
"Op07": {
"key": 105,
"operation": "insert"
},
"Op08": {
"operation": "removeMax"
},
"Op09": {
"key": 1755,
"newKey": 2634,
"operation": "change"
},
"Op10": {
"operation": "removeMax"
},
"metadata": {
"maxHeapSize": 5,
"numOperations": 10
}
You can create these files using the executable createheapoperationdata.exe. After
running build heap, my output2
"1": {
"key": 2634,
"leftChild": "2",
"rightChild": "3"
},
"2": {
"key": 105,
"parent": "1"
},
"3": {
"key": 2109,
"parent": "1"
},
"metadata": {
"maxHeapSize": 5,
"max_size": 5,
"numOperations": 10,
"size": 3
}
Here, the top-level keys are either node data or metadata. The root node, a.k.a. node 1,
has key 2634, its left child has key 105 (node with index 2), and its right child has key
2109 (node with index 3). Each node must contain the following key value pairs:
key: the key the node contains.
parent: the index of its parent node, if it exists (i.e. if it is not the root).
leftChild: the index of its left child, if it exists. Otherwise, this field must be omitted.
rightChild: the index of its right child, if it exists. Otherwise, this field must be omitted.
The metadata must contain the following key value pairs:
maxHeapSize: defined from the input file, this is the maximum heap size possible.
max_size: the max_size of the priority queue passed during construction.
numOperations: defined from the input file, this is the maximum heap size possible.
size: the number of elements in the priority queue.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started