I have a first-in-first-out queue implementation such that when it is first initialized, a malloc is called to set aside memory for items that will be placed on the queue. When I am done with the queue, how do I free up the memory?
My code for the queue is as follows:
typedef Edge Item;
void QUEUEinit(int);
int QUEUEempty(void);
void QUEUEput(Item);
Item QUEUEget(void);
static Item *q;
static int N,head,tail;
void QUEUEinit(int maxN)
{q = malloc((maxN+1)*sizeof(Item));
N = maxN+1; head=N; tail=0;}
int QUEUEempty()
{ return head % N == tail;}
void QUEUEput(Item item)
{ q[tail++] = item;
tail = tail % N;}
Item QUEUEget()
{ head = head % N;
return q[head++];}