473,785 Members | 2,235 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3422

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...@gmai l.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.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
Nov 2 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3122
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
1943
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 structures */ struct node { struct node *next;
2
4453
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 */ #include <time.h>
10
35102
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 using queue or dqueue to implement it ... any good info is appreciated . I want it to be efficient , high speed for developing device drivers .
7
20014
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 cost. STL vector is suitable for removing form tail? or it is as costly as removing from middle? any other std container to serve this purpose? (note , I dont need linked list implementation of any container, as I want random access)
2
19182
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 program's problem or the library's problem. The libraries I am using is the boost and stl. The original program is quite long and I shrink it short and still able to duplicate the error. Basically, I first create a priority queue and after several round...
2
2964
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 store up to 10 items? Output from my code: Enter you choice: 1 Enter ID document to print : 21 Enter you choice: 1 Enter ID document to print : 22
1
6187
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 linked list Delete() – Deletes a string from the linked list Search() – Search for a string and return 1 if found otherwise return 0. isEmpty() – Returns 1 if the list is empty and 0 otherwise. Display() – Display all the strings in the list. ...
12
4055
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 the shared memory. I run fedora 9 and gcc 4.2. I am able to insert values in to the list, remove values from the list, but the problem is in traversing the list. Atlease one or 2 list nodes disappear when traversing from the base of the list or...
0
9484
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10350
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7505
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.