At 8/25/2010 07:49 PM, you wrote:
>On 8/25/2010 3:35 PM, Rick wrote:
> > I have a structure that I need to use in a linked list. Below is an
> > example of the structure. I need to link filled-in structures
> > together and need to print the list as well as search and sort on
> > various fields. I'll have to write the sort comparisons and somehow
> > link them to the standard list.
> >
> > Is this possible using C++ lists? How?
> >
> >       struct entryNode
> >       {
> >           entryNode           *Prev;      // Pointer to the previous node
> >           entryNode           *Next;      // Pointer to the next node
> >           long int            line;
> >           long int            nodeID;
> >           unsigned long       size;
> >           string              path;
> >           string              file;
> >           string              extension;
> >           int                 version;
> >           string              data;
> >       };
> >
>
>First, remove the node pointers and IDs and all that junk. Next, you
>create a list like this:
>
>    #include <list>
>
>    ...
>
>    std::list<entryNode> myList;
>
>You can then add items to the list, use iterators, etc. I think you're
>reading too far into this, or approaching it from a C perspective. Just
>create a list using your type as the template parameter, and call
>functions on it or use iterators. Don't worry about managing nodes or
>pointers. Let the compiler and libstdc++ authors do that for you.
>
>--
>John Gaughan
>http://www.johngaughan.net/
Thank you, John. This helps. But how do I create a class around this 
so I can add my own procedures? I need to format and display the 
elements in my structure, sort on various fields, search for a node 
by field, etc.

I can crate my class, but don't know how to setup the constructor to 
create a new instance of my class with the std::list as the base object.

And, yes, I'm still thinking in C I guess.

~Rick 

Reply via email to