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