Linked list

Discussion in 'C++' started by Kay, Aug 31, 2004.

  1. Kay

    Kay Guest

    If I want to use a for loop to display the context of the linked list,
    how to write this call ?
     
    Kay, Aug 31, 2004
    #1
    1. Advertising

  2. Kay wrote:
    > 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
     
    Victor Bazarov, Aug 31, 2004
    #2
    1. Advertising

  3. Kay wrote:
    > 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
     
    Thomas Matthews, Sep 1, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Ritchey
    Replies:
    7
    Views:
    510
    emerth
    Jul 10, 2003
  2. Chris Ritchey

    Generating a char* from a linked list of linked lists

    Chris Ritchey, Jul 9, 2003, in forum: C Programming
    Replies:
    7
    Views:
    501
    emerth
    Jul 10, 2003
  3. fool
    Replies:
    14
    Views:
    540
    Barry Schwarz
    Jul 3, 2006
  4. joshd
    Replies:
    12
    Views:
    699
    John Carson
    Oct 2, 2006
  5. jawdoc
    Replies:
    9
    Views:
    803
    Chris Thomasson
    Mar 10, 2008
Loading...

Share This Page