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/