Question: Complete theListQueueimplementation by implementing the enqueuing and dequeuing functions inListQueue.c. To get an idea of how these functions should behave, you can refer to the
Complete theListQueueimplementation by implementing the enqueuing and dequeuing functions inListQueue.c.
To get an idea of how these functions should behave, you can refer to the diagrams above. You must implement them as described above.
Once you think that you have got the functions working, recompile and run the tests forListQueue:
make ... ./testListQueue The ListQueue implementation is:
//ImplementationoftheQueueADTusingalinkedlist
#include
#include
#include
#include"Queue.h"
typedefstructnode*Node;
structnode{
Itemitem;
Nodenext;
};
structqueue{
Nodehead;
Nodetail;
intsize;
};
/**
*Createsanewemptyqueue
*/
QueueQueueNew(void){
Queueq=malloc(sizeof(*q));
if(q==NULL){
fprintf(stderr,"couldn'tallocateQueue ");
exit(EXIT_FAILURE);
}
q->head=NULL;
q->tail=NULL;
q->size=0;
returnq;
}
/**
*Freesallresourcesassociatedwiththegivenqueue
*/
voidQueueFree(Queueq){
Nodecurr=q->head;
while(curr!=NULL){
Nodetemp=curr;
curr=curr->next;
free(temp);
}
free(q);
}
/**
*Addsanitemtotheendofthequeue
*/
voidQueueEnqueue(Queueq,Itemit){
//TODO
}
/**
*Removesanitemfromthefrontofthequeueandreturnsit
*Assumesthatthequeueisnotempty
*/
ItemQueueDequeue(Queueq){
//TODO
return0;
}
/**
*Getstheitematthefrontofthequeuewithoutremovingit
*Assumesthatthequeueisnotempty
*/
ItemQueueFront(Queueq){
assert(q->size>0);
returnq->head->item;
}
/**
*Getsthesizeofthegivenqueue
*/
intQueueSize(Queueq){
returnq->size;
}
/**
*Returnstrueifthequeueisempty,andfalseotherwise
*/
boolQueueIsEmpty(Queueq){
returnq->size==0;
}
/**
*Printsthequeuetothegivenfilewithitemsspace-separated
*/
voidQueueDump(Queueq,FILE*fp){
for(Nodecurr=q->head;curr!=NULL;curr=curr->next){
fprintf(fp,"%d",curr->item);
}
fprintf(fp," ");
}
/**
*Printsoutinformationfordebugging
*/
voidQueueDebugPrint(Queueq){
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
