I have having a problem with my dequeue function and I was wondering if someone
ID: 3732152 • Letter: I
Question
I have having a problem with my dequeue function and I was wondering if someone could help me? My problem is that it works out the for the first 3 items I dequeue but after that it does not dequeue at all.
template <typename DataType>
DataType QueueArray<DataType>::dequeue() throw (logic_error)
{
DataType temp;
temp = dataItems[front];
if (back == front && front == 0)
{
front = -1;
back = -1;
}
else {
front++;
}
if (isEmpty())
{
front = -1;
back = -1;
}
else if (front >= maxSize)
{
front = 0;
}
return temp;
}
Explanation / Answer
template <typename DataType>
DataType QueueArray<DataType>::dequeue() throw (logic_error)
{
DataType temp;
temp = dataItems[front];
if (isEmpty())
{
front = -1;
back = -1;
}
else if (front >= maxSize)
{
front = 0;
}
front++;
return temp;
}
Can you try it now ?