Linked list

K

Kay

If I want to use a for loop to display the context of the linked list,
how to write this call ?
 
V

Victor Bazarov

Kay said:
If I want to use a for loop to display the context of the linked list,
how to write this call ?

Assuming that 'list_t' is the type of your list class, and that
'next' member of that class designates the link to the next node,
and that 'data' member of that class designates the contents of
each node, something like:

for (list_t* p = &mylist; p != NULL; p = p->next)
display(p->data);

V
 
T

Thomas Matthews

Kay said:
If I want to use a for loop to display the context of the linked list,
how to write this call ?
If you were using std::list, you could use std::list::iterator
and a "for" loop. Or use something from <algorithms>.

Have you taken any courses on Data Structures?

Also, you may progress faster by purchasing a book on
data structures. Posting every single problem you encounter
to this newsgroup is a slow method.


--
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,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top