Problem with Circular Linked Queue Program



 DEVELOP > c-Plus-Plus > Problem with Circular Linked Queue Program

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "shanknbake"
Date: 01 Nov 2006 04:17:07 PM
Object: Problem with Circular Linked Queue Program
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
.

User: "doug turnbull"

Title: Re: Problem with Circular Linked Queue Program 01 Nov 2006 04:56:12 PM
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.
.
User: "shanknbake"

Title: Re: Problem with Circular Linked Queue Program 01 Nov 2006 05:03:04 PM
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.com> wrote:

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.

.


User: "Alan Johnson"

Title: Re: Problem with Circular Linked Queue Program 01 Nov 2006 06:34:08 PM
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
.
User: "Alan Johnson"

Title: Re: Problem with Circular Linked Queue Program 01 Nov 2006 06:44:28 PM
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
.
User: "shanknbake"

Title: Re: Problem with Circular Linked Queue Program 01 Nov 2006 07:03:00 PM
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.com> wrote:

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

.




  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER