#ifndef MINPRIORITYQUEUE_DEFINED #define MINPRIORITYQUEUE_DEFINED /* File MinPriorityQueue.h. Header file for a MinPriorityQueue containing elements of type PQEntry. PQEntry must be defined on the command line when any source file including MinPriorityQueue.h is compiled, e.g., gcc -Wall -DPQEntry=Event MinPriorityQueue.c where Event is a structure type. In a MinPriorityQueue, a remove operations always removes the "smallest element". Since the elements may be of structure or pointer type, we cannot decide which element is smallest by comparing elements using <. The program using a MinPriorityQueue must supply a function Boolean f( PQEntry a, PQEntry b); that returns true if a should be treated as less than b. A pointer to this function is then passed to the function CreateMinPriorityQueue that creates the MinPriorityQueue. */ #ifndef PQEntry #error Error: PQEntry not defined in the compile command. #endif #include "mcs360.h" typedef struct MinPriorityQueue MinPriorityQueue; /* createMinPriorityQueue(less) creates a new MinPriorityQueue, initializes it to empty, and returns a pointer to it. The argument less is a pointer to a function that tells us when one element of type PQEntry is treated as less than another; a is treated as less that b is less(a,b) is true. */ MinPriorityQueue *CreateMinPriorityQueue( Boolean (*less)(PQEntry,PQEntry)); /* DestroyMinPriorityQueue(pq) frees the dynamic memory used by MinPriorityQueue pq. */ void DestroyMinPriorityQueue( MinPriorityQueue *pq); /* add(item,pq) adds item to MinPriorityQueue pq. */ void add( PQEntry item, MinPriorityQueue *pq); /* removeMin(pq) removes a "smallest" element on MinPriorityQueue pq, and returns it. Here a "smallest" element on pq is an element x such that less(y,x) is false for all y on pq. */ PQEntry removeMin( MinPriorityQueue *pq); /* min(pq) returns a "smallest" element (as defined above) on MinPriorityQueue pq, without removing it from pq. */ PQEntry min( const MinPriorityQueue *pq); /* empty(pq) returns true if MinPriorityQueue pq is empty.*/ Boolean empty( const MinPriorityQueue *pq); /* size(pq) returns the number of elements in the MinPriorityQueue pq. */ int size( const MinPriorityQueue *pq); #endif