By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,234 Members | 1,872 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,234 IT Pros & Developers. It's quick & easy.

Problem with Circular Linked Queue Program

P: n/a
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

Nov 1 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a

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
Is it kosher to get help from others like this on your school project,
I know for many schools it is an honor code violation. The kinds of
help and who you can ask may be restricted by your school or instructor.

Nov 1 '06 #2

P: n/a
I agree completely doug, however I'm not asking for someone to write
the code for me..but merely to look over the code I've written and
point out an obvious mistake...which I'm over looking.

On Nov 1, 2:56 pm, "doug turnbull" <pythag...@gmail.comwrote:
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
-KevinIs it kosher to get help from others like this on your school project,
I know for many schools it is an honor code violation. The kinds of
help and who you can ask may be restricted by your school or instructor.
Nov 1 '06 #3

P: n/a

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

Nov 2 '06 #4

P: n/a

Alan Johnson wrote:
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.
This also seems to plague your deque function and your destructor.
Mentally step through your dequeue function for the case when count==1
and think about what happens.

Also, your destructor tries to clean up by looping through your list
until it hits NULL, which just won't ever happen in a circular queue.
I suggest reusing your dequeue logic (after you fix it) for the
destructor. That is, just keep calling dequeue until count == 0.

--
Alan Johnson

Nov 2 '06 #5

P: n/a
thanks Alan,
Let me put these ideas into effect and see what i come up with. I'll
keep you posted of any success.
-Kevin

On Nov 1, 4:44 pm, "Alan Johnson" <a...@yahoo.comwrote:
Alan Johnson wrote:
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.This also seems to plague your deque function and your destructor.
Mentally step through your dequeue function for the case when count==1
and think about what happens.

Also, your destructor tries to clean up by looping through your list
until it hits NULL, which just won't ever happen in a circular queue.
I suggest reusing your dequeue logic (after you fix it) for the
destructor. That is, just keep calling dequeue until count == 0.

--
Alan Johnson
Nov 2 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.