Queues, adding and deleting elements

Hello all,
I have a quiz regarding queues tomorrow and am still questions the notation for a given addElement & deleteElement function. I understand the concept behind queues but am stuck on how to turn it into code. For example, in order to add an element to a given queue would you write a function something like this?:

addElement (int & rear, int jeffsQ[], int newEl)
{
if (!fullStack())
{ rear ++; //this is where confusion arises
Q[rear] = newEl;
}
else
cout << "The stack is full" << endl;
}

I know the syntax might not be correct but I am confused on whether or not I just need to increase the rear by 1 or to use the modular formula (because of the specific problem of the front being the same as the rear in some cases) which looks like this..
rear = (rear+1) % maxQueueSize;
The computer science-y definition of a queue is a FIFO. Implemented as an array, you need two "pointers": one
that "points" to the first used index and one that "points" to the last used index. This, with just a little bit
of thought, should give you the answer.

If not, consider a simple example. Suppose the array has 5 elements. What should the queue look like after
each of the following steps:

add element (value = 42)
add element (value = 999)
add element (value = 36)
remove element [value returned is 42]
add element (value = 64)
add element (value = 100)
add element (value = 123456789)

That makes much more sense. Thank you. However, what should I code in order to make a boolean function that returns whether the queue is full. Would it be?:

bool fullQueue(int &front, int &front)
{
return rear == front - 1;
}
What is rear and front set to when the queue is empty?

Starting with those values, if you run the above steps I gave you with pencil and paper, you end up with the queue being
full. What are the values of rear and front at that time?
Oh I see, my teacher had us initialize the front and rear to -1 for some reason. Is that a problem or should I set them to 0 each?
It's not a problem.

So, if rear == front == -1 (not C++ expression!), then the queue is empty.

After the first line above (add element), what will rear and front be set to?
Topic archived. No new replies allowed.