C++ Implementing Lists Within Lists Using Structs/Classes

I am trying to conceptualize how to get started with a project to basically have two linear linked lists managed using a combination of structs and classes. The general format is to have a list of containers, with each possible container having its own list of contents. Visually something like:

1
2
3
4
5
6
7
[Container] -> [Container] -> [Container] -> NULL
     |              |
[  Item   ]    [   Item  ]
     |              |
[  Item   }        NULL
     |
   NULL


I'm not having any difficulty with the initial list of containers, and have that implemented. Where I'm running into difficulty is how to manage the lists of items within a given container.

Is it better to have two list classes? That way each time I'm creating the lists of managed items I'm creating a new instance of that list class? Or is there something that's maybe easier that I'm missing?

Any help on how to get started would be great.

Caveats:
No use of the list class.
I'm not quite to the point of vectors, etc.

Let me know if anyone has any helpful advice.
a list of lists is fine. Ideally they would be the same thing, via a template...
eg mylist <mylist <dataclass> > everything; //a list of lists of dataclass

If you don't know templates, you can either mimic them with some horrid thing (union or pointers can both do it) or just make 2 list classes (this is not ideal at all, best avoided, is extra work).

consider, without templates being available, ..
struct node
{
mylist* mlp;
dataclass* dcp;
node * next;
};

class mylist
{
node * me; //this can be either a list or a dcp.
}

mylist foo;
foo.me ->mlp->me->dcp.something; //a piece of data, public access issue aside.

or uglies
foo.me->next->me->mlp->me->dcp .... //first item in second list in the list of lists. If I did that right.



Last edited on
Topic archived. No new replies allowed.