[an error occurred while processing this directive]
In this sub-project, you will implement one class:
A heap is said to be stable if two objects which are placed into the heap with the same value or priority, it follows that they will come out in the same order in which they were placed into the heap.
Suggestion: first get a binary heap working and only once it works perfectly for different integers should you try to add the stability.
This class stores a fixed number of values in a binary minimum heap which is stable in the following sense: if two equal objects are placed into the heap, the object which was placed into the heap first is the first to be removed. If there are zero elements in the heap, the heap is said to be empty. The constructor is passed the capacity as an argument (defaulting to 10). The binary heap is to be implemented as is desribed in the course notes; however, some modifications will be necessary. The object at the top of the heap is always the smallest object of all objects in the heap (a min heap).
The process by which equal objects will be tracked is as follows: starting with 0, the first object entered into the heap is paired with the key 0, e.g., (x1, 0). Following this, each successive object is given the next largest integer key. The key is never reset under any conditions. When determining order, use lexicographical ordering: (u, v) < (x, y) if u < x or u = x and v < y.
Basically, it is a binary heap where you keep track of a second array and if you make a swap in the first array (the standard heap), you make a similar swap in the second.
Because we are using integers and doubles to test your class, we will have access through the functions Type retrieve( int n ) const and int key( int n ) const.
Use whatever member variables you feel are necessary. Some member variables are suggested; however, you are welcome to modify them.
Stable_binary_heap( int n = 10 )
This allocates enough memory for a heap capable of storing n objects.
Any memory you allocated must be cleaned up. (O(1))
Create a copy of the object. (O(n))
Assign the heap to be an exact copy, in all respects, of the argument. (O(nrhs))
This class has eight accessors:
This class has three mutators: