Question: This week's labwork will be about Heap data structure. You are given a heap.h header file which contains a HeapNode class and Heap class. You

 This week's labwork will be about Heap data structure. You are

This week's labwork will be about Heap data structure. You are given a "heap.h" header file which contains a HeapNode class and Heap class. You are going to implement a min-heap. 1. The insert function is given as two parts. The first part is using Heap property to find the suitable location to add the given data to the Heap. For this purpose the code given to you includes a stack to hold the 0 or 1 values to navigate through the Heap. For example, 14276 8 In this heap, if insert is called the suitable location is the right child of the node 2. In order to find this, you can use the heap-size. In this example the heap size is 6, when a new node is added the size will become 7. In order to navigate through the heap and find the location of the right child of 2, you must start from root and go right and right again to arrive at the proper location. If you find the mod 2 of 7 it is 1 so it points to the right. Then you perform integer division of 7 by 2 to find 3. This points to right again. This process is given in the insert function. You must use this stack and add the given data to the heap. Then fix the heap if the added data breaks the min-heap property. (70 pts) insert(const T&new_data) insert(const T &new_data, HeapNode *node, stack &dir) 2. You must write the necessary code to navigate the heap using level order. Print the heap so that the min-heap structure can be verified. print_levelorder(HeapNode *node, int level) heap.h

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!