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 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 zeroargument constructor which creates a heap with the default capacity, a
named constant called DEFAULTCAPACITY 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 Capacity Values are
Write a method bool insertValueT 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 as the root, a node at index j can
find its left child if that node has a left child at index j and its right child if that node has a right child
as index j Conversely, the parent of each node except the root at index k can be found at index
k where the int data type automatically truncates the noninteger 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
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 multiline format
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
