shanknbake wrote:
Here is my code. I've noted where the program crashes. I'm doing this
program as a project for school.
//cqueue.h file
//HEADER FILE
http://rafb.net/paste/results/Nh0aLB77.html
--------------------------------------------------------------------
//cqueue.cpp file
//IMPLEMENTATION OF cqueue CLASS
http://rafb.net/paste/results/A2gXAr73.html
-------------------------------------------------------------------
//driver.cpp file
//DRIVER FILE
http://rafb.net/paste/results/iZbqug40.html
The problem appears to be in my driver file under Deletepassenger and
showpassenger functions.
Plz let me know if something pops out at u
thanks
-Kevin
Your enqueue logic seems suspect to me. You have:
tempPtr->next=NULL;
if(IsEmpty())
{
rear = tempPtr;
count++;
}
else if(!IsFull())
{
rear->next=rear;
rear = tempPtr;
count++;
}
If your queue is empty, then you wind up with a queue with a single
node whose next pointer points to NULL, which doesn't fit the
definition of a circular queue.
Assuming that first problem is fixed, the else case doesn't seem
correct either. You wind up with rear pointing to the new node, and
the rest of the queue is leaked.
Just off the top of my head (meaning not compiled or tested) I would
expect it to look something like:
if (IsEmpty())
{
rear = tempPtr->next = tmpPtr;
count++;
}
else if (!IsFull())
{
tempPtr->next = rear->next;
rear = tempPtr;
count++;
}
Note especially the base case of 1 node. It's next pointer should
point back to itself, or else there is nothing circular about the
queue.
--
Alan Johnson