Solved

queue issue

Posted on 1998-11-13
7
163 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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.

803 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