priorityqueue.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // include guard
  2. #ifndef PRIORITYQ_H
  3. #define PRIORITYQ_H
  4. #include "json.hpp"
  5. class PriorityQueue{
  6. int *heapArray; // pointer to heap array
  7. int max_size; // max size of heap array
  8. int heap_size; // elements in heap
  9. void swap(int*, int*); // swaps two keys in the heap
  10. void heapifyUp(int); // moves keys up if they are larger than their parent key
  11. void heapifyDown(int); // moves keys down if they are smaller than their parent key
  12. public:
  13. // required functions from PDF
  14. void insert(int); // inserts a new key into heap
  15. void removeMax(); // removes the maximum value key (the root)
  16. void removeKey(int); // removes the key with the specific value
  17. void change(int, int); // changes the value of one key for a new, given value
  18. // helpful functions
  19. void printJSONTree(int, int); // prints the heap as a JSON object
  20. void initiateHeap(int); // initiates a heap with the given capacity in the heap
  21. void deleteHeap(); // deletes the array at the end to avoid memory leaks
  22. int returnMax(); // returns the value of the root
  23. };
  24. // initiate functions
  25. void insert(int key);
  26. void removeMax();
  27. void removeKey(int key);
  28. void change(int key, int newKey);
  29. void heapifyUp(int index);
  30. void heapifyDown(int index);
  31. void printJSONTree(int, int);
  32. void initiateHeap(int capacity);
  33. int returnMax();
  34. void deleteHeap();
  35. void swap(int*, int*);
  36. #endif