Now you are asked to do the followings 1 Add void ReverseQue
Now, you are asked to do the followings: 1. Add void ReverseQueue(queueADT queue); prototype into queue.h interface: 2. Implement this function under both array and list representations. That is, add its implementation into both qarray.c and qlist.c files When Implementing this function, make sure that you will use the original memory cells and do not allocate any additional storage (of course you can use local variables) 3. Modify qtest.c client/driver program so that a user can reverse the existing queue by calling the above function that is just added to the interface. 4. Finally say make and compile qtest.c with new qarray.c and qlist.c. Then test both arrayqtest and list-qtest programs....
---------qarray.c------------
--------------qlist.c------------
-------qtest.c--------
-------What I came up for qarray.c------
void ReverseQueue(queueADT queue){
int tail = queue->tail;
int head = queue->head;
int size = tail - head +1;
int halfSize = size/2;
int index;
for(index = head; index <(head+halfSize); index++) {
int temp = queue->elements[index];
queue->elements[index] = queue->elements[tail-index];
queue->elements[tail-index] = temp;
}
}
//Stuck with qlist.c any help would be much needed.
Solution
void ReverseQueue(queueADT queue){
cellT *cp;
cellT *nxt;
cellT *prev;
cp = New(cellT *);
nxt = New(cellT *);
prev = New(cellT *);
prev = NULL;
if(queue->head == NULL)
return;
cp = queue->head;
while(cp != NULL) {
nxt = cp->link;
cp->link = prev;
prev = cp;
cp = nxt;
}
queue->head = prev;
}

