| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- // include guard
- #ifndef PRIORITYQ_H
- #define PRIORITYQ_H
- #include "json.hpp"
- class PriorityQueue{
- int *heapArray; // pointer to heap array
- int max_size; // max size of heap array
- int heap_size; // elements in heap
- void swap(int*, int*); // swaps two keys in the heap
- void heapifyUp(int); // moves keys up if they are larger than their parent key
- void heapifyDown(int); // moves keys down if they are smaller than their parent key
- public:
- // required functions from PDF
- void insert(int); // inserts a new key into heap
- void removeMax(); // removes the maximum value key (the root)
- void removeKey(int); // removes the key with the specific value
- void change(int, int); // changes the value of one key for a new, given value
- // helpful functions
- void printJSONTree(int, int); // prints the heap as a JSON object
- void initiateHeap(int); // initiates a heap with the given capacity in the heap
- void deleteHeap(); // deletes the array at the end to avoid memory leaks
- int returnMax(); // returns the value of the root
- };
- // initiate functions
- void insert(int key);
- void removeMax();
- void removeKey(int key);
- void change(int key, int newKey);
- void heapifyUp(int index);
- void heapifyDown(int index);
- void printJSONTree(int, int);
- void initiateHeap(int capacity);
- int returnMax();
- void deleteHeap();
- void swap(int*, int*);
- #endif
|