Hello everyone....again.
I have a program that is using a queue. I have a class member function that is to traverse the queue, and output the smallest number in the queue.
Pseudo for this function is:
Compare the front and front->next. Whichever is smaller, keep it. Traverse the queue until each node had been evaluated (yes, I know this is not an efficient way to do things, but is quick and dirty for what I need.)
Here is the code snippet. If you think you need more, I'll be happy to post the rest.
void dynintqueueEX::smallest()
{
queuenode *temp;
// CHECK FOR EMPTY QUEUE
if(front == NULL)
{
cout<< "\nQUEUE IS EMPTY! \n";
}
//step through qeueu - starting with front
//to find the smallest number in the queue
for(int a = 0; a <= NULL; a--)
{
temp = front;
if(front >= front->next)
{
temp = front->next;
cout << "The low value this step is: " << front->value << endl;
}
}
//cout << "\nTHE SMALLEST NUMBER IN QUEUE IS: " << top->value;
}
I commented out the last cout for debugging purposes. I put the cout inside the loop to let me know what the program was doing through each pass. Currently, as shown above, it results in an infinite loop. If I change a-- to a++ it only seems to evaluate the queue once.
This is probably something simple, but I've been staring at it too long. Any hints or help to prod me along is much appreciated.