Linked list

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kay

    #1

    Linked list

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

  • Victor Bazarov

    #2
    Re: Linked list

    Kay wrote:[color=blue]
    > If I want to use a for loop to display the context of the linked list,
    > how to write this call ?[/color]

    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

    Comment

    • Thomas Matthews

      #3
      Re: Linked list

      Kay wrote:[color=blue]
      > If I want to use a for loop to display the context of the linked list,
      > how to write this call ?
      >[/color]
      If you were using std::list, you could use std::list::iter ator
      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:

      C++ Faq: http://www.parashift.com/c++-faq-lite
      C Faq: http://www.eskimo.com/~scs/c-faq/top.html
      alt.comp.lang.l earn.c-c++ faq:

      Other sites:
      http://www.josuttis.com -- C++ STL Library book

      Comment

      Working...