Queue empty after display !!!

K

Kay

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;
}
 
T

Tim Love

Kay said:
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?
 
K

Karl Heinz Buchegger

Kay said:
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.
 
T

Thomas Matthews

Kay said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top