In: Computer Science
C++ Heap Tree: Make a program called "priority_queue" that has the following operations using a heap and simulating a prioritized row of integers with higher priority value.
I would appreciate if someone could help me with this code
It has to include the following on the code:
push
Description: Add data to prioritized row
Entry: An integer, which you want to add to the prioritized row
Exit: Nothing
Precondition: n is an integer
Postcondition: The prioritized row contains new data.
pop -
Description: Remove the data with the highest priority from the prioritized row
Entry: Nothing
Exit: Nothing
Precondition: That the prioritized row contains at least 1
data.
Postcondition: The prioritized row is left without the data with
the highest priority
top
Description: Returns the value of the data that is with the highest priority in the prioritized row.
Entry: Nothing
Output: The data that has the highest priority within the
prioritized row
Precondition: That the prioritized row contains at least 1
data.
Postcondition: Nothing
empty
Description: Returns a boolean value saying if the prioritized row is empty or has data.
Entry:Nothing
Output: A boolean value that tells whether the prioritized row is
empty or has data.
Precondition: Nothing.
Postcondition: Nothing
size
Description: Returns the amount of data that the prioritized row has
Entry :Nothing
Output :An integer value representing the amount of data in the
prioritized row
Precondition: Nothing.
Postcondition: Nothing
It has to include the next class header
#ifndef MYHEAP_H
#define MYHEAP_H
class MyHeap{
private:
int* values; //where the HEAP values are going to be saved
int size; //Represents how many values the Heap has stored
public:
MyHeap(); //Initialize the attributes. The values attribute initializes it as an empty array size 7
void push(int
n); // Insert a value in the heap. Only when the new value does not
fit in the array
// grow the array to size 2 * n + 1. (Dynamic expansion of the
array)
// That is, if you already have the arrangement with 7 values and
you want to insert another value (The 8th)
// then the array is grown to size 15, the first 7 values of the
original array are copied
// and the 8th value is inserted.
void pop(); //A value is removed from the heap. It is never necessary to decrease the size of the array.
int top(); //Return who is the next element to exit but without deleting it
bool isEmpty(); //returns true if the heap is empty otherwise returns false
int length(); //returns how many elements the heap is storing
};
#endif