Hi!
It's not quite like that. Class #2 is really simple (I don't see that one in your example code). It has one data element and a pointer to the next element (which is NULL at first). It is accessible and searchable in one direction only (head to tail).
Class #1 has other data elements and a pointer to the next list element for #1. It also has an instance of Class #2 declared like this: SecondClass class2;
I didn't use a pointer, just a straight declaration as if it were any normal variable, struct, etc.
The destructor in each queue type just 'pops' the elements out of the list out and deletes their reserved space until there is nothing left in the list anymore. I assume the head and tail pointers declared inside the class are deleted on their own in the 'normal' way and returning function dumps temporary variables.
I should try to be as specific as I can. Here is more pseudo code of the function call:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
int main()
{
while(1) {
function_with_queues();
//when I get back here, I want all the memory used by the queues to be freed
}
}
void function_with_queues(void)
{
QueueOne q1;
//Work with q1, build it up based on data from user
//Process the long list of q1 with a long list of q2 elements in each one
//Provide user with some solution
}
|
I'm basically just trying to make a linked list with another linked list embedded inside of it so that each link in the chain of #1 can have a list of dynamically created integers stored in list #2. There might be code examples out there for this but I haven't found one yet.
Thanks for jumping in to help,
Orad