Hello. I am trying to build a program that will print the convex hull of n points, but in order to do this i was told to implement a priority queue using heap. This should store the coordinates x and y of one point and the key is suppossed to be the distance between two points. The first problem that I have is trying to implement the priority queue using heap, because we briefly talked in class about it and i have no example. I tried to google it, this is what I have now but of course, it's not working.
class priority_queue_overflow{}; //daca prin insert se incearca marirea dimensiunii lui A, se arunca exceptia priority_queue_overflow()
class priority_queue_underflow{}; //daca extract_min se apeleaza pe un heap gol, atunci se arunca exceptia priority_queue_overflow()
class priority_queue{
private:
class arrayH {
public:
int x;
int y;
double key;
};
arrayH* A; //vectorul/array-ul folosit pentru a stoca heap-ul
int heapsize; //dimensiunea curenta a heap-ului
int size; //dimensiunea curenta a vectorului: nu se schimba
void heapify(int k);
public:
priority_queue(int n); //don't forget to allocate the array of size n+1 as we don't use slot zero
~priority_queue(); //delete the array
bool empty(); //true/false daca heap-ul este gol sau nu
void insert(int x, int y, double priority); //adauga punctele x si y in heap, cu cheia de prioritate aferenta
/* insert */
void priority_queue::insert(int x, int y, double priority) //add s to the heap with the given priority as its key
{
if (heapsize == size) {
throw priority_queue_overflow();
}
// facem loc pentru insert
++heapsize;
// Adaugam coordonata x a punctului
A[heapsize].x = x;
//Adaugam coordonata y a punctului
A[heapsize].y = y;
// desemnam cheia de prioritate membrului
A[heapsize].key = priority;
// loop through and trickle up as needed
int i(heapsize);
while (i > 1 && A[parent(i)].key > A[i].key) {
std::swap(A[parent(i)], A[i]);
i = parent(i);
}
}
int main()
{