I'm learning queues from a book. The author explains the operation of inserting an element in queue using the following code.
#define MAX 100
char *p[MAX];
int spos = 0; // spos: holds the index of the **next free** storage location
int rpos = 0;// rpos: holds the index of the next item to retrieve
void qstore(char *q)
{
if(spos==MAX) {
printf("List Full\n");
return;
}
p[spos] = q;
spos++;
}
So according to the above code, a queue is full if spos=100 i.e the last element in the array. Now, since spos holds the index of the next free storage location, then when spos=100, the last position in the array is empty. So why is it explained as List full? Shouldn't this code be modified such that it allows the last position in the array to be filled or am I missing something very obvious?
Thanks.