Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

queue issue

Posted on 1998-11-13
7
Medium Priority
?
182 Views
Last Modified: 2010-04-01
null
0
Comment
Question by:strev
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

972 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