Question: Problem 1 in the next Programming Assignment will ask students to define a MinHeap class in order to implement a minheap. In this lab, you'll

Problem 1 in the next Programming Assignment will ask students to define a MinHeap class in order to
implement a minheap. In this lab, you'll get a start on that assignment by defining the MinHeap class in the
files MinHeap.h and MinHeap.cpp and by implementing a few methods.
Turn in a functional MinHeap.h file that defines all the methods requested in this lab. It would be best to
use the supplied typedef statement that defines a data type T that represents the data type of each value of
the heap, in a manner we've seen in previous labs and assignments. Your class should include methods for
retrieving both the capacity of the heap and the current size of the heap.
In MinHeap.cpp, write a zero-argument constructor (which creates a heap with the default capacity, a
named constant called DEFAULT_CAPACITY), and a constructor where the user passes the desired capacity
of the heap. Also write a destructor to deallocate the dynamically allocated array!
Write int getSize() and int getCapacity() accessor methods.
Write a void display() method that will print out the values in the heap. Simply print the values in a single
line, for example: Size =8, Capacity =15, Values are 36871291523
Write a method bool insertValue(T newValue) that inserts a new value into the heap. This will require that
you insert the new value at the "end" of the heap (checking the heapCapacity data member to see if there's
room, and if so, also incrementing the heapSize data member), then performing the comparisons and swaps
necessary to maintain the Heap Property. This method should return true is the value was successfully
inserted and false if not (for example, if the heap is already full and has no room for an additional value).
HINT: Remember that when using an array to hold a heap with index 0 as the root, a node at index j can
find its left child (if that node has a left child) at index 2j+1 and its right child (if that node has a right child)
as index 2j+2. Conversely, the parent of each node (except the root) at index k can be found at index
(k-1)/2 where the int data type automatically truncates the non-integer part of the result.
Write a method T removeValue() that removes the value at the root of the heap. This will also require that
you then move the value at the "end" of the heap to the root (and decrementing the heapSize data
member), then performing the comparisons and swaps necessary to maintain the Heap Property. If the
heap is empty, the method should return -99999.
Use the code in the supplied main function to populate your heap with values using the insertValue
method, then print the array containing the heap, and maybe even print the heap in the multi-line format
Problem 1 in the next Programming Assignment will

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 Programming Questions!