Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Queue empty after display !!!

Reply
Thread Tools

Queue empty after display !!!

 
 
Kay
Guest
Posts: n/a
 
      09-02-2004
how to display a queue context without removing it's item ? It is
possible to do that ? I have run below function. However, after running
it, the queue is empty. Did I do sth wrong ?

while( Queue != NULL ){

tmp = q->front;

cout << tmp->item << tmp->cuisine << tmp->mode << endl;

q->front = tmp->next;
}

 
Reply With Quote
 
 
 
 
Tim Love
Guest
Posts: n/a
 
      09-02-2004
Kay <(E-Mail Removed)> writes:

>how to display a queue context without removing it's item ? It is
>possible to do that ? I have run below function. However, after running
>it, the queue is empty. Did I do sth wrong ?


> while( Queue != NULL ){
>
> tmp = q->front;
>
> cout << tmp->item << tmp->cuisine << tmp->mode << endl;
>
> q->front = tmp->next;
> }

What is Queue? Should you be resetting q->front? Why not do tmp=tmp->next?
 
Reply With Quote
 
 
 
 
Karl Heinz Buchegger
Guest
Posts: n/a
 
      09-02-2004
Kay wrote:
>
> how to display a queue context without removing it's item ? It is
> possible to do that ? I have run below function. However, after running
> it, the queue is empty. Did I do sth wrong ?
>
> while( Queue != NULL ){
>
> tmp = q->front;
>
> cout << tmp->item << tmp->cuisine << tmp->mode << endl;
>
> q->front = tmp->next;
> }


Read again the reply I sent when I introduced strcmp to you.
It shows a code exmple an how to do this.

--
Karl Heinz Buchegger
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Thomas Matthews
Guest
Posts: n/a
 
      09-02-2004
Kay wrote:
> how to display a queue context without removing it's item ? It is
> possible to do that ? I have run below function. However, after running
> it, the queue is empty. Did I do sth wrong ?
>
> while( Queue != NULL ){
>
> tmp = q->front;
>
> cout << tmp->item << tmp->cuisine << tmp->mode << endl;
>
> q->front = tmp->next;
> }
>


Read the reply I posted to you. I told you
that you were removing elements from the queue.

Remember that you're Queue is based on a linked list.
Remember that the final link in a linked list is NULL.
Remember that to go from one link to another, you
follow the "next" field.

Something like:
tmp = q->front;
while (tmp != NULL)
{
// Visit or process the node:

cout << tmp->item << '\n';
cout << tmp->cusine << '\n';
cout << tmp->mode << '\n';
cout << endl;

// Advance to the next node:

tmp = tmp->next;
}

Note that since your node fields are all char *
that if you display them like your example above
they will all "run into each other" and you will
not see the separation. Most people will use
a separation character or characters, such as
a newline (like my example), tabs, or surround
the text with double quotes (").

Now let us see if you will actually read any of
these replies and implement their suggestions...

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Why queue.empty() returns False even after put() is called? Cameron Simpson Python 0 11-23-2012 10:19 PM
Why queue.empty() returns False even after put() is called? Peng Yu Python 2 11-23-2012 06:53 PM
Program blocked in Queue.Queue.get and Queue.Queue.put Kris Python 0 01-04-2012 03:46 PM
Is Queue.Queue.queue.clear() thread-safe? Russell Warren Python 4 06-27-2006 03:03 PM
Queue.Queue-like class without the busy-wait Paul L. Du Bois Python 29 04-04-2005 01:28 PM



Advertisments