I am working on circular array, but I don't think I understand it fully (yet)
I have created this code but I don't think it is working as it should, specially part that needs to remove item from queue.
As i understand this should work as FIFO (First in First Out). I am not sure how to remove items from array. At the moment I am replacing it with different number and in my code it just work same way as ADD to array but it replace number from last element (if that makes sense??) where as when I add new element it adds from Top to bottom. (I might have to switch names ;) top and bottom )
is my understanding correct that variables front and back decide if array is empty?
I am not looking for a fix ;) more advise where are problems with my code :)
1. Try to not do I/O in your functions (expect the ones whose purpose is I/O, like `showQueue()')
a. If you are not going to use a parameter, then don't ask for it.
1 2 3 4 5 6
void put(int item) // put member on array
{
this->back = (this->back % Queue::MAX);
this->number[this->back] = item;
this->back++;
}
(this is not needed, just wanted to remark that you are working on the caller object)
1 2 3
void showQueue()
{
for (int i = 0; i < MAX; i++)
wrong, show the queue from front till back.
that would also solve the remove part, you don't need to replace the item, just adjust the indices to leave it outsite.
thank you for that!!! I am sorry about late reply I was in work and now I am at my c++ evening course I will read/re read and re read again :) and try to sort my code :)
void get function is to (as per my book) to get away item from array. but I think pop is more readable.