#include #include #include #include "rtimer.h" #include "pqheap.h" /* this is the file with the definition of a pqueue element */ #include "basictype.h" const int size=1000; int main() { PQueue* pq; Rtimer rtInsert, rtDelete, rtTotal; int i; elemType elt, e[size]; char buf[1000]; rt_start(rtTotal); /* start total timer */ rt_start(rtInsert); /* start insert timer */ pq = PQ_initialize(); for (i=0; i<1000; i++) { e[i].error = 1.0/i; e[i].otherstuff = i; PQ_insert(pq, e[i]); } rt_stop(rtInsert); /* stop insert timer */ PQ_print(pq); rt_start(rtDelete); /* start delete timer */ while (!PQ_isEmpty(pq)) { assert(PQ_extractMin(pq, &elt)); /* elt should be identical with e[elt.otherstuff] */ assert(elt.error == e[elt.otherstuff].error); assert(elt.otherstuff == e[elt.otherstuff].otherstuff); } PQ_delete(pq); rt_stop(rtDelete); /* stop delete timer */ rt_stop(rtTotal); /* stop total timer */ printf("test passed. PQ may be working..\n"); /* print times */ printf("times:\n"); rt_sprint(buf, rtInsert); printf("insert time: %s\n", buf); rt_sprint(buf, rtDelete); printf("delete time: %s\n", buf); rt_sprint(buf, rtTotal); printf("total time: %s\n", buf); return 1; }