Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

queue issue

Posted on 1998-11-13
7
Medium Priority
?
178 Views
Last Modified: 2010-04-01
null
0
Comment
Question by:strev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 5

Expert Comment

by:scrapdog
ID: 1177857
In your DeQueue, shouldn't you check if the pointer is not NULL *before* you go ahead and delete it?  
0
 

Author Comment

by:strev
ID: 1177858
i don't understand what you mean.  I don't believe this answers my question, but thanks.
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1177859
void IntQueue::Dequeue()
{
NodePtr tempPtr = front;
if (tempPtr != NULL )
  {
    front = tempPtr->link;
    delete tempPtr;
    if (front == NULL)
    rear = NULL;
  }
}

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:strev
ID: 1177860
Very interesting and it works.  Now my issue is why?  How is it that front was being set to NULL in my original Dequeue implementation?  If you have time please respond.  And how do I arrange to get you your points?
0
 
LVL 4

Expert Comment

by:pluim
ID: 1177861
The code is kind of hard to read without indentation, but
it looks like you DeQueue regardless of whether something
was EnQueued first - you only call EnQueue if the
customer number > 0, but the DeQueue is called regardless
of the number.
Track the number of enqueues and dequeues with a debug
statement - the number should be the same.

As for arranging to get scrapdog his well deserved points,
he just has to put his solution (or any dummy text) in
as an answer, nothing you can do until then.

(ah, the joys of consumer/producer programming....)

pluim.


0
 
LVL 5

Accepted Solution

by:
scrapdog earned 400 total points
ID: 1177862
Thanks pluim for explaining it.  I was just looking through the code and trying to come up with a way to explain it, but it looks like you explained it pretty well.

The line I added is simply an error checking line that will stop the program from attempting to dequeue when the queue is empty.
0
 

Author Comment

by:strev
ID: 1177863
Thanks again for the solution as well as the explanation.  In future questions, I promise to indent as well.  Pardon the faux pas.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question