473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

Nov 1 '06 #1
5 3395

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
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

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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Kay | last post by:
I would like to ask a question about linked list and queue. 1) Can each node of linked list contain a queue ? 2) Is it the same queue or different queue ?
16
by: Shwetabh | last post by:
Hi, This is a question asked to me in an interview. I haven't been able to figure out an answer for it. Please try to see what can be done about the following problem. /* I have been given two...
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
10
by: avsrk | last post by:
Hi Folks I want to create a circular queue for high speed data acquistion on QNX with GNU C++ . Does any one know of efficient ways either Using STL or in any other way . I am thing of ...
7
by: toton | last post by:
Hi, I want a circular buffer or queue like container (queue with array implementation). Moreover I want random access over the elements. And addition at tail and remove from head need to be low...
2
by: zl2k | last post by:
hi, I have one program runs fine on my i386 linux box but get the "glibc detected *** corrupted double-linked list" error on the x86_64 linux box. Please help me to figure out if it is my...
2
by: lavender | last post by:
When define a maxQueue is 10, means it able to store 10 items in circular queue,but when I key in the 10 items, it show "Queue Full" in items number 10. Where is the wrong in my code? Why it cannot...
1
by: yaarnick | last post by:
Create a linked list data structure library to hold strings. Then library should support the following linked list operations. Create() – Creates the linked list Insert() – Insert a string into the...
12
by: kalyan | last post by:
Hi, I am using Linux + SysV Shared memory (sorry, but my question is all about offset + pointers and not about linux/IPC) and hence use offset's instead on pointers to store the linked list in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.