Question: Implement a min - heap class in Java. ( a ) The keys are of type int. ( b ) Your class shall be named
Implement a minheap class in Java.
a The keys are of type int.
b Your class shall be named as follows:
caucalgary.cpscMinHeap
c Your class shall implement the following Java interface:
package caucalgary.cpsc;
public interface PriorityQueue
boolean empty;
boolean full;
void insertint key;
int extractMin;
int min;
d The minheap has a capacity of
e Your implementation shall check for underflow and overflow of
the heap, and throws
appropriate exceptions when such situations arise.
f The class shall provide a constructor that does not take any
arguments. This constructor
initializes the heap to an empty one.
g The class shall override the toString method. Your
implementation of
toString shall return a String in the following format:
The string consists of multiple lines, each terminated by a
newline character. No
line shall contain leading or trailing whitespaces.
The first line shall look like this:
size
The size of the heap is the number of cells that are actually
occupied. Of course,
your binary heap may have a different size.
Subsequent lines list the keys stored in the binary heap, from
low indices to high
indices. Elements belonging to the same height shall belong to the
same line. Adjacent elements are separated by a single blank space.
For example, the following
lines list the elements of a minheap.
Hint: Note that Java array indices start from zero rather than
one
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
