Solved

queue issue

Posted on 1998-11-13
7
159 Views
Last Modified: 2010-04-01
null
0
Comment
Question by:strev
  • 3
  • 3
7 Comments
 
LVL 5

Expert Comment

by:scrapdog
Comment Utility
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
Comment Utility
i don't understand what you mean.  I don't believe this answers my question, but thanks.
0
 
LVL 5

Expert Comment

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

0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:strev
Comment Utility
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
Comment Utility
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 100 total points
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now