Hi,
I have this code fragment that is suppose to find the max value in a queue. It seemed to work fine until I switched up the locations of the letters being fed into the queue.
It is suppose to compare each element of the queue and return the largest number/letter.
somehow it seems like it might be just comparing the first and last queue location and I dont understand why . Can anybody tell me what's wrong with the code .
//**************************************************************************
//SomeType Max() const;
// Max()
// Returns largest data value found within queue WITHOUT
//modifying the queue.
// Throws EmptyQueue if queue is empty
//**********************************************************************
SomeType Queue:: Max() const {
if(IsEmpty()){
throw EmptyQueue();
}
QueueNode* tempPtr;
SomeType tempValue;
tempPtr=frontPtr;
while((tempPtr)!=NULL){
tempValue=tempPtr->data;
if(tempValue<(tempPtr->data))
{
tempValue=tempPtr->data;
}
tempPtr=tempPtr->nextPtr;
}
delete tempPtr;
return tempValue;
}