nested loop use example

Discussion in 'C++' started by Willie, Nov 1, 2003.

  1. Willie

    Willie Guest

    I am trying to get an inner class IntNode to encapsulate the nodes of
    the linked list with the outer class having having a simple integer
    value for data storage. So far I just can't see how this becomes
    useful as with my current implementation it is just a pain to declare
    everything. There must be a better way or at least there must be a
    great pay off in some situations to go through this information as to
    either would be of great help thanks.


    William
    Willie, Nov 1, 2003
    #1
    1. Advertising

  2. Willie wrote:
    > I am trying to get an inner class IntNode to encapsulate the nodes of
    > the linked list with the outer class having having a simple integer
    > value for data storage. So far I just can't see how this becomes
    > useful as with my current implementation it is just a pain to declare
    > everything. There must be a better way or at least there must be a
    > great pay off in some situations to go through this information as to
    > either would be of great help thanks.
    >
    >
    > William


    In a simple linked list, there is no need to have separate classes
    for data and for links. Templates are very useful when you don't
    know the data type or for having an algorithm or class work with
    any data type.

    template<class Data_Type>
    struct Node
    {
    Data_Type data;
    Node * next;
    };

    If you want to get complicated:
    template<class Data_Type>
    struct Double_Link_Node
    : public Node<Data_Type>
    {
    Node<Data_Type> * previous;
    };

    Although for a doubly linked list, I would just put both link
    fields in the same structure.

    If this is not for homework, try the STL std::list<> container.
    It is already written and tested.


    --
    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.raos.demon.uk/acllc-c /faq.html
    Other sites:
    http://www.josuttis.com -- C++ STL Library book
    http://www.sgi.com/tech/stl -- Standard Template Library
    Thomas Matthews, Nov 1, 2003
    #2
    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. so.intech
    Replies:
    4
    Views:
    591
    so.intech
    Aug 9, 2006
  2. David Williams
    Replies:
    2
    Views:
    478
    David Williams
    Nov 29, 2005
  3. ThatsIT.net.au

    Looking for simple nested gridview example

    ThatsIT.net.au, Oct 11, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    1,167
    ThatsIT.net.au
    Oct 12, 2007
  4. Sam Roberts
    Replies:
    15
    Views:
    277
    Sam Roberts
    Feb 7, 2005
  5. Isaac Won
    Replies:
    9
    Views:
    352
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page