#include #include #include #include "priority_queue.hpp" using namespace std; int main() { // PQ is an open ended data structure -> alloc an arbitrary mem amount PriorityQueue *pq = new(malloc(1024 * 1024)) PriorityQueue(); // macro helpers #define I(v) { uint s=pq->length; pq->insert(v,10*v); if (s+1 != pq->length) return -1; } #define T(v) { if (pq->minVal() != v || pq->minPayload() != 10*v) return -1; pq->removeMin(); } #define DP { for (uint i=0; ilength; i++) { cout << pq->heap[i].val << ", "; } cout << "-" << endl; } // add and remove some values I(3); I(2); I(1); T(1); T(2); T(3); // add many random values srand(42); for (int i=0; i<100000; i++) { // cout << "."; pq->insert(rand(), 0); } unsigned int prev = 0; for (int i=0; i<100000; i++) { if (pq->minVal() < prev) return -1; prev = pq->minVal(); pq->removeMin(); } // got until here -> success return 0; }