This is the struct:
struct Node {
Node *nodes[MAX]
};
So inside the struct, we have an array of pointers to more Node structures, and so on.
Basically the initial node is allocated for (using new Node), and then we allocate space for any Node that we need to use.
ie.
Node *full = new Node();
Node *another = new Node();
full->nodes[30] = another;
All other pointers are set to NULL.
Since I did not use any new [] anywhere, I don’t need to use delete [], correct?
You can add a constructor and a destructor to your
Nodestruct:So now you just need to delete the root node and all the children will get recursively deleted at the same time. Note that the constructor is there to ensure the array is zeroed out. You don’t want to end up calling delete on uninitialized memory! Also note that calling delete on NULL is a valid operation that does nothing (if you use the standard allocator).
EDIT: even though you say in the comments that you don’t care, it might be a good idea to disable copies and assignments in your struct, as I’ve done above. This will prevent you from shooting yourself in the foot and deleting the same memory twice.