Solved

queue issue

Posted on 1998-11-13
7
161 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.

910 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

24 Experts available now in Live!

Get 1:1 Help Now