Hey guys, so I'm having some trouble with this program I am trying to write. Here is the main code: http://pastebin.com/y6yQX8K8
So, I have to write the functions to pop, push, and expand the q. Here is what I have for the pop:
1 2 3 4 5 6 7
//function to pop
Order SandwichQueue::pop()
{
if(isEmpty)
return;
--somevariable; //Not sure what this should be?
}
and this is what I have so far for the push function:
1 2 3 4 5 6 7 8 9 10
//push an element, make sure it is not full, if it is call expand funciton
void SandwichQueue::push(const Order& sw)
{
if((rear+1) % qSize == front)) //Checks to see if the queue is full
SandwichQueue::expandQ(); //Calls the expand function if full
else
sQ[++back] = sw; //Assigns sw to sQ if not full.
}
I guess my questions are what should I be looking at for the decrementing in the pop function, and does the push function look correct? I would compile it but I'm missing the expand function, which I don't think I have covered in class yet; I can't just double size can I? Can anyone lend me some hints maybe?
//function to pop
Order SandwichQueue::pop()
{
if(isEmpty())
return NULL;
front = (front + 1) % qSize;
return Order[front];
}
//push an element, make sure it is not full, if it is call expand funciton
void SandwichQueue::push(const Order& sw)
{
if(((back+1) % qSize == front)) //Checks to see if the queue is full
SandwichQueue::expandQ(); //Calls the expand function if full
back = (back + 1) % qSize;
sQ[back] = sw; //Assigns sw to sQ if not full.
}
//Double the queue size, copy the values, and reset back and front
void SandwichQueue::expandQ()
{
Order tempQ[initialSize * 2];
for(int i = 0; i < size(); i++)
{
tempQ[i].sandwich = testCases[i].sandwich;
tempQ[i].customerName = testCases[i].customerName;
tempQ[i].orderNbr = testCases[i].orderNbr;
tempQ[i].fries = testCases[i].fries;
}
delete [] testCases;
*Order = tempQ;
back = initialsize - 1;
front = 0;
}
Questions I have are, in the pop function, how do I return the correct data? Order[front]? I'm not sure if I have it right, because then I'm confused in the push function because I have sQ[back]. Also, I'm not sure what I have done wrong in the expand function, or if it's close to being right at all.